[rules-users] How can generated facts/events be published?
Edson Tirelli
tirelli at post.com
Sun Aug 29 20:35:20 EDT 2010
Try:
// this is type of control fact
declare MsgSent
msg : StatusMessage
end
rule publish
when
$msg : StatusMessage( )
not MsgSent( msg == $msg )
then
// publish
insert( new MsgSent( $msg ) ); // using 5.1.1, otherwise needs to use
empty constructor and set the field
end
rule cleanup
when
$snt : MsgSent( )
not StatusMessage( this == $snt.msg )
then
retract( $snt );
end
Edson
2010/8/29 Tina Vießmann <tviessmann at stud.hs-bremen.de>
> Thank you, Wolfgang! :)
>
> 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.
>
> -W
>
>
> On 29 August 2010 19:16, Tina Vießmann <tviessmann at stud.hs-bremen.de>wrote:
>
>> Hi,
>>
>> I've got a simple question.
>>
>> How can I get generated facts out of the memory (for publishing them
>> using JMS)?
>>
>> Thanks :)
>> Tina
>> _______________________________________________
>> rules-users mailing list
>> rules-users at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
>
>
> _______________________________________________
> rules-users mailing listrules-users at lists.jboss.orghttps://lists.jboss.org/mailman/listinfo/rules-users
>
>
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
--
Edson Tirelli
JBoss Drools Core Development
JBoss by Red Hat @ www.jboss.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20100829/27f33be2/attachment.html
More information about the rules-users
mailing list