我是这个的新手,如果我的错误看起来很愚蠢,请原谅我。我正在使用带有玻璃鱼和日食的主动mq。我已经在玻璃鱼中创建了JMS资源,例如目标资源和连接工厂。 Active Mq正在运行,我已经在glassfish上部署了消息驱动bean,并且没有异常发生,但是我在active mq上找不到我的队列,并且控制台上也没有打印消息。
我基本上使用的是此处给出的示例:https://www.javatpoint.com/message-driven-bean
public class MessageSender {
public static void sendMessage() throws JMSException, NamingException {
InitialContext ctx = new InitialContext();
QueueConnectionFactory f = (QueueConnectionFactory) ctx.lookup("jms/myQueueConnectionFactory");
QueueConnection connection = f.createQueueConnection();
connection.start();
QueueSession ses = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
Queue t = (Queue) ctx.lookup("jms/myQueue");
QueueSender sender = ses.createSender(t);
TextMessage message=ses.createTextMessage("Hello !!! Welcome to the world of ActiveMQ.");
sender.send(message);
connection.close();
}
}
@MessageDriven(mappedName = "jms/myQueue")
公共类MessageReceiver实现MessageListener {
/**
* Default constructor.
*/
public MessageReceiver() {
// TODO Auto-generated constructor stub
}
/**
* @see MessageListener#onMessage(Message)
*/
public void onMessage(Message message) {
// TODO Auto-generated method stub
TextMessage m=(TextMessage) message;
try{
System.out.println("message received: "+m.getText());
}catch(Exception e){System.out.println(e);}
}