To programmatically subscribe to Event Hub or Event Analytics with your own Java class:
Write the Java code, get the libraries from the Event Hub and Event Analytics applications in the Infor Grid, download the simple SLF4J logger, compile, and run. I used this code for my demo of picking lists in Google Glass; I would not use this in a production environment.
DISCLAIMER: INFOR DOES NOT SUPPORT USAGE OF CUSTOM SUBSCRIBER OR PUBLISHER CLIENTS IN EXTERNAL APPLICATIONS. ONLY INFOR PROCESS AUTOMATION (IPA) AND M3 ENTERPRISE COLLABORATOR (MEC) ARE ALLOWED TO CONNECT TO THE EVENT HUB. USE AT YOUR OWN RISK. MAY VOID YOUR WARRANTY.
/* javac -cp eventhub-common-2.0.20.jar;eventhub-subscriber-2.0.20.jar;slf4j-api-1.6.2.jar TestEventSubscriber.java java -cp eventhub-common-2.0.20.jar;eventhub-subscriber-2.0.20.jar;slf4j-api-1.6.2.jar;hornetq-core-client-2.3.0.CR1.jar;hornetq-commons-2.3.0.CR1.jar;slf4j-simple-1.7.12.jar;jboss-logging-3.1.0.GA.jar;jboss-logmanager-1.2.2.GA.jar;netty-3.6.2.Final.jar;. TestEventSubscriber */ import java.util.Date; import java.util.HashMap; import java.util.Map; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.lawson.eventhub.ElementData; import com.lawson.eventhub.EventData; import com.lawson.eventhub.Subscription; import com.lawson.eventhub.Subscription.Builder; import com.lawson.eventhub.subscriber.EventReceiver; import com.lawson.eventhub.subscriber.Subscriber; import com.lawson.eventhub.subscriber.SubscriberException; public class TestEventSubscriber { static String name = "MyTest"; static String hostName = "host"; static int portNumber = 22110; static String subscription = "M3:OCUSMA:U"; // or EventAnalytics:something static Subscriber subscriber; static Logger log = LoggerFactory.getLogger(TestEventSubscriber.class); public static void main(String[] args) throws Exception { register(); Runtime.getRuntime().addShutdownHook(new Thread() { /* stop when CTRL+C */ public void run() { try { unregister(); } catch (Exception ex) { log.error("CTRL+C", ex); } } }); } public static void register() throws Exception { log.info("Registering..."); // create subscriber Map<String, String> params = new HashMap<String, String>(); params.put("subscriber-name", name); params.put("subscriber-persist", "false"); params.put("subscriber-server-address", hostName); params.put("subscriber-server-port", Integer.toString(portNumber)); subscriber = new Subscriber(params); // add subscription Subscription sub = Subscription.newBuilder(subscription).build(); subscriber.add(sub); // register receiver EventReceiver receiver = new TestEventReceiver(); subscriber.register(receiver); // probe log.info( "isActive: " + subscriber.isActive() + ", isConnected: " + subscriber.isConnected() + ", isRegistered: " + subscriber.isRegistered() + ", isFailed: " + subscriber.isFailed()); } public static void unregister() throws Exception { log.info("Unregistering..."); subscriber.unregister(); } } class TestEventReceiver implements EventReceiver { static Logger log = LoggerFactory.getLogger(TestEventReceiver.class); public boolean receiveEvent(EventData event) throws SubscriberException { log.info( "Subscription: " + event.getSubscription() + ", Publisher: " + event.getPublisher() + ", DocumentName: " + event.getDocumentName() + ", Operation: " + event.getOperation().character() + ", TrackingId: " + event.getTrackingId() + ", SentTimestamp: " + new Date(event.getSentTimestamp()).toString() + ", CONO: " + event.getElementValue("CONO")); for (ElementData element : event.getElements()) { log.info( "Name: " + element.getName() + ", OldValue: " + element.getOldValue() + ", Value: " + element.getValue()); } return true; } }
It will persist a file data/subscriber/delivered/MyTest.rcv
that contains a bunch of unique ids and that you can deserialize with a ConcurrentHashMap.
Thank you.
UPDATE 2015-05-05: Added the disclaimer.
LikeLike
UPDATE: Subscriptions are un-aunthenticated and un-encrypted by default (yikes!). Event Hub can be configured with TLS to authenticate the client and encrypt traffic. To be tested.
LikeLike
thibaudatwork – would you contact me to collaborate? you are pushing the envelope and I would like to meet you Joanna_Bledsoe@Dell.com
LikeLike
Joanna, thank you for the feedback. I will send you an email.
LikeLike
Hello Thibaud. I have one question about CMS045 settings. I set up CMS045 with the CREATE event subscription (on OASITN file, item/assortment) and it’s working fine : a record is added into CUGEX1 any time i add a record in OIS072. Now if i delete the same record in OIS072, i go through the rule in EventAnalytics (i see my System.out.println in the log) but it does not delete the record in CUGEX1. Is it working as designed ? You can create, update but not delete ? Thank you !
LikeLike
Hi Max. I don’t know, I haven’t used CMS045 much. I didn’t even know it added records in CUGEX1. When you delete a record from OIS072, does it add a new record in CUGEX1 with operation=Delete or something? I would expect it to always append records. I would be surprised if it deleted records.
LikeLike
The creation of records in CUGEX1 is only due to the “event fields mapping” related option i set up. I think you are right, it can only create/update records in other tables, even with a DELETE operation. You could mark the record as “deleted” in this extension table file (put a status 90 in a free field for example) but i will never physically delete the record. Yeah, except a SQL statement in the rule! Thank you for your answer ; )
LikeLike
Hi maxric,
I’m working with eventhub and CMS045 event field mapping and my problem is that two or more process are subscribed to MITBAL update and will insert to CUGEX1. The second rule is having problem with duplicate key and I was planning on moving to CUGEX3. I was wondering though if I can create a new entry in CMS045 wherein instead of MITBAL event name I’ll use MITBAL1. Because event field mapping this time will be CUGEX3 and not CUGEX1. I was wondering if this is possible. Or should it always be the name of the table?
LikeLiked by 1 person
Hi Doms,
Sorry i just see your comment, it’s too late i guess ! You can add a subscription in CMS045 on event MITBAL1 (publisher EventAnalytics), correct. And this event MITBAL1 should be the one fired by EventAnalytcis (in the smart rule). In EventAnalytics, create a rule to subscribe to M3, mode CREATE on file MITBAL (add your different filters if needed) and fire event MITBAL1 in the “then” clause of the smart rule. Hope it helps.
LikeLike
Oh, good to know. Although we opted to use MEC and CUSEXTMI instead and we just manipulated the keys so that we can insert multiple MITBAL rows in CUGEX1.
LikeLike
Super article. Is that possible to test the all values with all old values to trigger only the real modifications.
thank you for your response, best regards
LikeLike
Yes, it’s all Java, so feel free to iterate the arrays.
LikeLike
Thank you for your response. In fact I want to test the set of values with the old values in a rule, I do not arrive elementdata does not even after import. Maybe there is a property or method of HubEvent or something else. thank you for your response, best regards
LikeLike
If you are in a Drools Rule, then refer to my other posts
https://m3ideas.org/2015/04/28/java-code-in-event-analytics-rules/
https://m3ideas.org/2015/05/14/call-m3-api-from-event-analytics-rules/
LikeLike
Thanks for your work thibaudatwork, I should find my solution in the post https://m3ideas.org/2015/05/14/call-m3-api-from-event-analytics-rules/
LikeLiked by 1 person
Hi Thibaud, How did we achieved “MyTest” in subscribers list on Event hub Grid management pages?
LikeLike
Once you run the code, it becomes a subscriber, and Event Hub adds it to the list.
LikeLike
Thanks , I have gone well till compilation. I am trying to run it from local C:\ drive , its trying to find .rcv file and saying as file not found .
Can you help on from where should we should run this class file ?
LikeLike
There was some mismatch with jar files , it worked now. Thanks
LikeLike