Message start event and JMS (best practice)

719 views
Skip to first unread message

Klime

unread,
Jun 8, 2014, 7:55:19 PM6/8/14
to camunda-...@googlegroups.com
Hi,

i wrote some code to start a process when a JMS message arrives. Everything works fine so far.
But i wonder if my solution is recommende pratice or are there better solutions to solve this problem?

1) bootstrapping of the process engine (extend ServletProcessApplication)
2) create a new thread in the "post deploy"-method

  @PostDeploy
  public void start(ProcessEngine processEngine) {
    System.out.println("Invoking @PostDeploy annotation in " + getClass().getName());    

    JMSListener jmsListener = new JMSListener();
    Thread jmsListenerThread = new Thread(jmsListener);
    jmsListenerThread.start();
  }

3)  loop in the thread waiting for messages to arrive, process the message an do a REST call to start a process instance

@Override
public void run() {
 try {
  consumer = new JMSConsumer();
  while(true) {
  Object message = consumer.listen();
  if(message instanceof ObjectMessage) {
  ObjectMessage objectMessage = (ObjectMessage)message;
 
  HashMap<String, Object> msgData = (HashMap<String, Object>)objectMessage.getObject();
 
  // process the message and start process instance whith REST call
  postData(msgData,url);
 
  System.out.println("messageName:" + msgData.get("messageName"));
  System.out.println("businessKey:" + msgData.get("businessKey"));
  System.out.println("processVariables:" + msgData.get("processVariables"));
  }
  }  
 } catch (Exception e) {
  System.err.println(e);
 } finally {
  consumer.close();
 }
}

In the postData-Method there ist just a simple REST call using HttpURLConnection and the jackson-library.

regards
Klime

Bernd Rücker (camunda)

unread,
Jun 9, 2014, 4:17:00 AM6/9/14
to camunda-...@googlegroups.com

Hi Klime.

 

Personally I would recommend to use an Java EE app server if you do JMS – then you can simply use Message Driven Beans (calling the Java API injected by CDI) and the container keeps track of all the bootstrapping. My colleague Falko once did an example on this: https://github.com/camunda/camunda-consulting/blob/master/snippets/asynchronous-messaging-jms/src/main/java/org/camunda/bpm/example/asynchronous_messaging_jms/CallbackServiceMDB.java.  

No option for you?

 

Cheers

Bernd

--
You received this message because you are subscribed to the Google Groups "camunda BPM users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camunda-bpm-us...@googlegroups.com.
To post to this group, send email to camunda-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/camunda-bpm-users/6107f55e-34bb-40e3-87ac-569b18264873%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Klime

unread,
Jun 9, 2014, 4:32:40 PM6/9/14
to camunda-...@googlegroups.com
Ok, thx. The MDB approach sounds good.

Currently i'm using Tomcat for developing some examples.
Don't know, perhaps i will try it with JBoss if enough time is left.
Reply all
Reply to author
Forward
0 new messages