Murali krishna
Murali krishna

Reputation: 823

Drools Spark Streaming integration for stateful kiesession

I am working with drools and spark streaming. I want to maintain the KieSession throughout the job in the spark streaming context. Each session for each worker node in spark. I understand that kiesession is where the facts are inserted and queried upon. According to my understanding session is the one which actually builds the rete network and inserts the facts in to alpha and beta memories. So my idea is to create a each kiesession for each working name throughout the job so that states are maintained in the kiesession. But i am not able to broadcast the kiesession because it is not serialized. Is there any other method to achieve only a single stateful session(KieSession) for each worker node in spark streaming context.

Upvotes: 3

Views: 467

Answers (1)

Mykhaylo Adamovych
Mykhaylo Adamovych

Reputation: 20966

You can marshall / unmarshal KieSession using org.kie.api.marshalling.Marshaller, here is javadoc for org.kie.internal.marshalling.MarshallerFactory

The MarshallerFactory is used to marshal and unmarshal StatefulKnowledgeSessions. At the simplest it can be used as follows:

// ksession is the StatefulKnowledgeSession
// kbase is the KnowledgeBase
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Marshaller marshaller = MarshallerFactory.newMarshaller( kbase );
marshaller.marshall( baos, ksession );
baos.close();

Upvotes: 0

Related Questions