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