我使用 JavaEE 8 full profile 开发 Liberty 18.0.0.2。
我在 server.xml 上使用以下内容配置了 JMS 2:
<?xml version="1.0" encoding="UTF-8"?>
<server description="new server">
<featureManager>
<feature>javaee-8.0</feature>
<feature>localConnector-1.0</feature>
<feature>wasJmsServer-1.0</feature>
<feature>wasJmsClient-2.0</feature>
</featureManager>
<basicRegistry id="basic" realm="BasicRealm" />
<httpSession securityIntegrationEnabled="false" />
<httpEndpoint id="defaultHttpEndpoint" httpPort="8080" httpsPort="9443" />
<applicationManager autoExpand="true" />
<applicationMonitor updateTrigger="mbean" />
<messagingEngine>
<queue id="simpleQueue" />
</messagingEngine>
<jmsActivationSpec id="jms/simpleQueue">
<properties.wasJms destinationRef="java:app/simpleQueue" />
</jmsActivationSpec>
</server>
现在我为 Liberty Application 服务器上的测试 JMS 编写了简单的代码:
@Stateless
public class MessageSender {
@Inject
private JMSContext context;
@Resource(lookup = "java:app/simpleQueue")
private Queue queue;
public void sendMessage(String message) {
context.createProducer().send(queue, "hello");
}
}
@Path("/messenger")
public class Messenger {
@Inject
private MessageSender messageSender;
@Path("/send")
@GET
public Response send() {
messageSender.sendMessage("Hello Mahdi");
return Response.ok("ok").build();
}
}
@MessageDriven(
name = "simpleQueue",
mappedName = "java:app/simpleQueue",
activationConfig = {
@ActivationConfigProperty(propertyName = "destinationType",
propertyValue = "javax.jms.Queue"),
@ActivationConfigProperty(propertyName = "destination",
propertyValue = "app/simpleQueue")
})
public class MessageReceiver implements MessageListener {
@Override
public void onMessage(Message message) {
System.out.println(message);
}
}
你能解释一下为什么 MessageListener 不起作用吗?
有什么错误?
我在谷歌搜索并找到了一些示例,但无法理解如何解决这个问题!.