Back to Browse

JBoss eap 6.4 integration with ActiveMQ

4.3K views
Oct 8, 2019
19:00

JBoss eap 6.4 integration with ActiveMQ and consuming messages remotely. 1. Java class to send messages to ActiveMQ ------------------------------------------------------------------ import org.apache.activemq.ActiveMQConnectionFactory; import javax.jms.*; public class Publisher { private Connection connection; private Session session; private Queue queue; private MessageProducer sender; private ActiveMQConnectionFactory connectionFactory; private String brokerUrl; private String username; private String password; private String queueName; public Publisher() { this.brokerUrl = "tcp://192.168.56.102:61616"; this.username = "jbossamq"; this.password = "jbossamq123"; this.queueName = "HelloworldQ"; connectionFactory = new ActiveMQConnectionFactory(this.username, this.password, this.brokerUrl); } public void initQueueConnection() throws Exception { connection = connectionFactory.createConnection(); session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); queue = session.createQueue(queueName); sender = session.createProducer(queue); } public void sendMsgToQueue(String serviceInput) throws Exception{ initQueueConnection(); TextMessage requestTextMessage = session.createTextMessage(serviceInput); sender.send(requestTextMessage); sender.close(); session.close(); connection.close(); } public static void main(String[] args) { Publisher pub = new Publisher(); try { pub.sendMsgToQueue("helloworld"); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } ============================================ 2. java class to consume the messages package org.jboss.as.quickstarts.mdb; import java.util.logging.Logger; import javax.ejb.ActivationConfigProperty; import javax.ejb.MessageDriven; import javax.jms.JMSException; import javax.jms.Message; import javax.jms.MessageListener; import javax.jms.TextMessage; import org.jboss.ejb3.annotation.ResourceAdapter; @MessageDriven(name = "HelloworldQ", activationConfig = { @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"), @ActivationConfigProperty(propertyName = "destination", propertyValue = "HelloworldQ"), @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge") }) @ResourceAdapter(value="activemq-ra.rar") public class HelloWorldQueueMDB implements MessageListener { private final static Logger LOGGER = Logger.getLogger(HelloWorldQueueMDB.class.toString()); /** * @see MessageListener#onMessage(Message) */ public void onMessage(Message rcvMessage) { TextMessage msg = null; try { if (rcvMessage instanceof TextMessage) { msg = (TextMessage) rcvMessage; LOGGER.info("Received Message from queue: " + msg.getText()); } else { LOGGER.warning("Message of wrong type: " + rcvMessage.getClass().getName()); } } catch (JMSException e) { throw new RuntimeException(e); } } }

Download

1 formats

Video Formats

360pmp431.8 MB

Right-click 'Download' and select 'Save Link As' if the file opens in a new tab.

JBoss eap 6.4 integration with ActiveMQ | NatokHD