Get all rules

29 views
Skip to first unread message

Yuriy Petrov

unread,
Dec 2, 2019, 12:06:41 PM12/2/19
to Drools Development
Hello,

How can I get at run time the set of all rules (list of rule names at least) in kie base using Drools API?

Thanks,
Yuriy

Stathis Rouvas

unread,
Dec 3, 2019, 9:58:21 AM12/3/19
to Drools Development
Hi Yuiry,

one option would be to use the AgendaEventListener.
This way you should get all rules (names) fired or considered for firing.
I think that over time you would get all the rules (names) that are used.

Cheers.

Yuriy Petrov

unread,
Dec 3, 2019, 11:56:35 AM12/3/19
to Drools Development
Well, digging in Drools API javadocs I've found how to get what I need:
1. Get kie session object (there are various ways to get this object), then get kie base object from the session
2. Kie base class provides the method Collection<KiePackage> getKiePackages() - call this method
3. For every package in the returned collection run the package's method Collection<Rule> getRules()

That's it :)

Regards,
Yuriy
Reply all
Reply to author
Forward
0 new messages