I am extrapolating a little from your original question and your subsequent post, but I think this tutorial *may* point you in the right direction. It was actually written for a completely different purpose, but the way in which I have solved the problem of writing multiple XML files from one dataset, may aid you in an approach for this....
Could you please take a look at talend big data product which provides Spark batch and Streaming feature?
Watch the recorded webinar!
Accelerate your data lake projects with an agile approach
Create systems and workflow to manage clean data ingestion and data transformation.
Introduction to Talend Open Studio for Data Integration.