json-rules-engine icon indicating copy to clipboard operation
json-rules-engine copied to clipboard

Rule returning multiple events

Open jgoux opened this issue 8 years ago • 10 comments

Hello,

thanks for this great lib! 👍

Is there a reason why the rule can't return multiple events when it succeed ?

jgoux avatar Feb 27 '17 12:02 jgoux

@jgoux thanks, you're welcome!

No reason I can think of off the top of my head. Perhaps we'll look at adding this in a future release if there's enough demand.

In the meantime, you may be able to work around this by listing multiple events in the params:

let rule = {
  conditions: {
   /* ... */
  },
  event: {
    type: 'multiple-events',
    params: {
      event1: {
        /* any additional event 1 parameters */
      },
      event2: {
        /* any additional event 2 parameters */
      }
    }
  }
}

You would of course need to write a few lines of logic for handling the 'multiple-events' payload

CacheControl avatar Feb 27 '17 21:02 CacheControl

Indeed, it works well that way too. 👍 (I pass an array as the params)

event: {
    type: 'SUCCESS',
    params: [
      {
        type: 'INDUIRE_RESULTAT',
        params: {
          analyse: 'URFIN',
          resultat: 'F'
        }
      },
      {
        type: 'INDUIRE_RESULTAT',
        params: {
          analyse: 'FOO',
          resultat: 'BAZ'
        }
      }
    ]
  }

I can live with it for now, thanks for the tip @CacheControl :D

jgoux avatar Feb 28 '17 12:02 jgoux

Going to close this out as it doesn't seem to be gaining much traction, and the workaround has been reported to be successful.

CacheControl avatar Jul 05 '17 15:07 CacheControl

Hi @CacheControl , not sure if this is obsolete, but we at riskine would definitely love the feature discussed here. Cheers, Johannes

jseebacher avatar Dec 12 '22 18:12 jseebacher

Would greatly appreciate multi-event capability as well.

stephen-spiny avatar Aug 07 '23 23:08 stephen-spiny

Just a note, that the workaround proposed here would be incompatible with some new functionality that relies on the correct use of the params for a single event, e.g. Support Facts in Events.

honzabit avatar Aug 25 '23 08:08 honzabit

@honzabit This should still work, you just won't get the new feature. I'm reopening this issue and putting it into a version 7 wish list since it's going to need to be a breaking change.

chris-pardy avatar Aug 25 '23 13:08 chris-pardy

@chris-pardy - do we have something like pairing of conditions and events e.g condition 1 is successful, return event 1, condition 2 is successful, return event 2. Probably we are trying to implement something similar to Drools, which can process excel sheet as a set of separate conditions and separate output. [ { "Facts": { "name": "Kashif" } }, { "Condition": { "any": [ { "fact": "name", "operator": "equal", "value": "Kashif" } ] }, "Event": { "Result": { "Message": "Facts equal to Kashif" } } }, { "Condition": { "any": [ { "fact": "name", "operator": "notEqual", "value": "Kashif" } ] }, "Event": { "Result": { "Message": "Name not equal to Kashif" } } } ]

kashifrahman avatar Sep 15 '23 06:09 kashifrahman