Process with JMS Message

353 views
Skip to first unread message

mike.blo...@gmail.com

unread,
Sep 26, 2014, 6:15:44 AM9/26/14
to camunda-...@googlegroups.com
Hi there,

just started with camunda and wanted to create a little process where I have a service task with puts a message into a JMS queue on the glassfish server.

I used the example with the AbstractBpmnActivityBehaviour

Here is the code for the task with should send a message.

@Stateless
public class AsyncServiceTask extends AbstractBpmnActivityBehavior {

@Resource(mappedName = "jms/calculatorqueue")
private Queue queueMessage;
@Resource(mappedName = "jms/queueConnectionFactory")
private ConnectionFactory queueMessageConnectionFactory;

public static final String EXECUTION_ID = "executionId";

public void execute(final ActivityExecution execution) throws Exception {

// Build the payload for the message:
Map<String, Object> payload = new HashMap<String, Object>(
execution.getVariables());
// Add the execution id to the payload:
payload.put(EXECUTION_ID, execution.getId());

// Publish a message to the outbound message queue. This method returns
// after the message has
// been put into the queue. The actual service implementation (Business
// Logic) will not yet
// be invoked:
// MockMessageQueue.INSTANCE.send(new Message(payload));

sendMessage(payload);

}

private Message createMessage(Session session,
Map<String, Object> messageData) throws javax.jms.JMSException {
TextMessage tm = session.createTextMessage();
String id = (String) messageData.get(EXECUTION_ID);

tm.setText("Message with Execution id = " + id);
return tm;
}

private void sendMessage(Map<String, Object> messageData)
throws javax.jms.JMSException, NamingException {
Context c = new InitialContext();
Connection conn = null;
Session s = null;
try {
conn = queueMessageConnectionFactory.createConnection();
s = conn.createSession(false, s.AUTO_ACKNOWLEDGE);
MessageProducer mp = s.createProducer(queueMessage);
mp.send(createMessage(s, messageData));
} finally {
if (s != null) {
try {
s.close();
} catch (JMSException e) {
Logger.getLogger(this.getClass().getName()).log(
Level.WARNING, "Cannot close session", e);
}
}
if (conn != null) {
conn.close();
}
}
}

public void signal(ActivityExecution execution, String signalName,
Object signalData) throws Exception {

// leave the service task activity:
leave(execution);
}

}


Is that the correct way to do it? Somehow the ConnectionFactory does not get injected.

Here is my project:
https://drive.google.com/file/d/0B2s5Zdqufgk4Ymp2NjViYXpvWWc/edit?usp=sharing

If someone could help me get started, would be nice :)

Thanks
mike

Bernd Rücker (camunda)

unread,
Sep 26, 2014, 6:22:15 AM9/26/14
to camunda-...@googlegroups.com
Hi Mike.

You should use a JavaDelegate (instead of a AbstractBpmnActivityBehavior).
And If you want to use injections you have to make a CDI bean out of it and
attach it so a ServiceTask using a delegateExpression - then it should work.

Cheers
BErnd

-----Ursprüngliche Nachricht-----
Von: camunda-...@googlegroups.com
[mailto:camunda-...@googlegroups.com] Im Auftrag von
mike.blo...@gmail.com
Gesendet: Freitag, 26. September 2014 12:16
An: camunda-...@googlegroups.com
Betreff: [camunda-bpm-users] Process with JMS Message
--
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/1886fd34-dcbe-44f0-b2e0-3e3344d43c9c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

mike.blo...@gmail.com

unread,
Sep 26, 2014, 11:56:14 AM9/26/14
to camunda-...@googlegroups.com
Hi Bernd,
Could you provide an example for a CDI Bean and how to attach it?

Thanks
Mike

Bernd Rücker (camunda)

unread,
Sep 29, 2014, 3:41:33 AM9/29/14
to camunda-...@googlegroups.com
Hi Mike.

You have to use a delegateExpression (see
http://docs.camunda.org/latest/api-references/bpmn20/#tasks-service-task)
and this can point to a delegate being a CDI bean (see e.g. here
http://docs.camunda.org/latest/guides/user-guide/#cdi-and-java-ee-integration-expression-resolving).

Cheers
Bernd

-----Ursprüngliche Nachricht-----
Von: camunda-...@googlegroups.com
[mailto:camunda-...@googlegroups.com] Im Auftrag von
mike.blo...@gmail.com
Gesendet: Freitag, 26. September 2014 17:56
An: camunda-...@googlegroups.com
Betreff: Re: [camunda-bpm-users] Process with JMS Message
https://groups.google.com/d/msgid/camunda-bpm-users/c19e8c3d-784e-46ed-abb3-ccb89b3a68f5%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages