Тёмный

JBoss eap 6.4 integration with ActiveMQ 

Veerababu Anupoju
Подписаться 3,3 тыс.
Просмотров 4 тыс.
50% 1

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);
}
}
}

Опубликовано:

 

7 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 3   
@ruixue6955
@ruixue6955 2 года назад
3:03 4:30 add a queue in ActiveMQ server 4:55 have to connect to this broker in Jboss 6:20 change bind address in bootstrap.xml 8:22 *use remote jboss to consume the message* 8:29 9:45 standalone-full.xml - adapter config 10:48 download resource adapter jar 12:14 13:50 resource-adapter-ref 16:51 success deployment log
@nortonix894
@nortonix894 4 года назад
did you forget to bring the microphone from the basement?
@LearningJboss
@LearningJboss 4 года назад
will work on this