JMS Connection

Generated Objects

@Property(name = "myJmsConnection")
public ConnectionFactory myJmsConnection;

myJmsConnection is an instance of javax.jms.ConnectionFactory that represents the selected resource. You can use it to communicate with a JMS server.

Business Logic Example

	class MyJMSActivityExecutor implements Runnable {
		/**
		 * <!-- begin-custom-doc -->
		 * 
		 * <!-- end-custom-doc -->
		 * @generated
		 */
		@Override
		public void run() {
			if(getActivityLogger().isDebugEnabled()) {
				activityLogger.debug(RuntimeMessageBundle.DEBUG_PLUGIN_ACTIVITY_METHOD_CALLED
									,new Object[] { "Executor run()"
									,activityContext.getActivityName()
									,activityContext.getProcessName()
									,activityContext.getDeploymentUnitName()
									,activityContext.getDeploymentUnitVersion() });
				String serializedNode = XMLUtils.serializeNode(inputData, processContext.getXMLProcessingContext());
		    	activityLogger.debug(RuntimeMessageBundle.DEBUG_PLUGIN_ACTIVITY_INPUT, new Object[] {activityContext.getActivityName(), serializedNode});
			}
			
			try {		
				
				
									// begin-custom-code
									// add your own business code here		
				try {
					// create a server connection as per a JMS Connection Resource 
					Connection connection = myJmsConnection.createConnection();
					connection.start();
					Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
					TemporaryQueue tempQueue = session.createTemporaryQueue();
					MessageProducer producer = session.createProducer(tempQueue);
					TextMessage message = session.createTextMessage();
					// send some messages
					for (int i = 0; i < 3; i++) { 
					    message.setText("This is message " + (i + 1)); 
					    System.out.println("Sending message: " + message.getText()); 
					    producer.send(message);
					}
					// receive some messages
					MessageConsumer consumer = session.createConsumer(tempQueue);
					for (int i = 0; i < 3; i++) {
						Message receivedMessage = consumer.receive();
						System.out.println("Received message: " + receivedMessage.getBody(String.class));
					}
				} catch (JMSException e) {
					throw new ActivityFault(activityContext, e);					
				}
							// end-custom-code
				
				
								
				N output = null;
				SerializableXMLDocument<N> wrapper = new SerializableXMLDocument<N>(processContext.getXMLProcessingContext(), output);
				notifier.setReady(wrapper);
			} catch (Exception e) {
				e.printStackTrace();
				notifier.setReady(e);
			}
		}
	}