Let's say:
I'm generating StatusMessage objects during the rule processing.
They will be published. But they are also need for further
processing (so they can not be deleted after publishing).
The StatusMessage objects defined as simple POJOs.
If I'm publishing the StatusMessage objects using a rule like
rule 'publish StatusMessages'
when
$msg : StatusMessage( )
then
// publish
end
In this case every StatusMessage would be send again and again.
My first impression for a solution would be to define a Boolean
field 'send' that signals if the object has been send. But the field
would just be needed for Drools internal processing. So I thought of
defining this additional field using the declare statement. But if I
remember correctly from previous tries, such a things are not
possible because the declare statement with the additional field is
the definition of a new type... Am I right so far?
Do you have a idea how I can solve my problem of sending an
fact/event just once but keep it in the memory for further
processing?
Thank sou!
Tina
The usual method:
You establish a TopicPublisher as a global declared in your .drl
file.
global TopicPublisher topicPublisher
You must set this from Java code using
TopicPublisher topicPublisher = ...;
statefulKnowledgeSession.setGlobal( "publisher", topicPublisher
)
and then you use it in any RHS code.
Of course, a TopicPublisher could also be (field of) some fact,
but this shouldn't be necessary for such a central service.