简体   繁体   English

JMS MessageListener 不适用于 Liberty

[英]JMS MessageListener not working on Liberty

I working on Liberty 18.0.0.2 with JavaEE 8 full profile .我使用 JavaEE 8 full profile 开发 Liberty 18.0.0.2。
I configured JMS 2 on server.xml with this content :我使用以下内容在 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>     

now I wrote simple codes for test JMS on Liberty Application server :现在我编写了用于在 Liberty 应用程序服务器上测试 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);
    }
}   

Can you explain me why MessageListener not work ?你能解释一下为什么 MessageListener 不起作用吗?
What's mistake ?什么错误?
I search in google and found some examples , but can not understand how can fix this problem !我在谷歌搜索并找到了一些例子,但不明白如何解决这个问题! . .

You didn't provide any error messages, so more or less guessing here你没有提供任何错误信息,所以或多或少在这里猜测

You are missing queue definition:您缺少队列定义:

<jmsQueue jndiName="java:app/simpleQueue" id="simpleQueueJms">
    <properties.wasJms queueName="simpleQueue"/>
</jmsQueue>

Your MDB should be defined like this:您的 MDB 应如下定义:

@MessageDriven(name="SimpleMDB")
public class MessageReceiver implements MessageListener 

And active spec like this:和这样的活动规范:

<jmsActivationSpec id="yourAppName/SimpleMDB">
    <properties.wasJms destinationRef="simpleQueueJms" destinationType="javax.jms.Queue"/>
</jmsActivationSpec>

Update by request in comments.根据评论中的要求更新。

Application name depends on your application structure and deployment descriptors.应用程序名称取决于您的应用程序结构和部署描述符。 You may find details here - Deploying message-driven beans , but I'm quoting relevant part for reference:您可以在此处找到详细信息 - Deploying message-driven beans ,但我引用了相关部分以供参考:

The ID value must be in the format of application name/module name/bean name where: ID 值必须采用application name/module name/bean name的格式,其中:

  • application name is the name of the application that is deployed (for example, JMSSample). application name是部署的应用程序的名称(例如,JMSSample)。 The application name applies only if the bean is packaged within an EAR file.仅当 bean 打包在 EAR 文件中时,应用程序名称才适用。 The application defaults to the base name of the EAR file with no file name extension unless specified by the application.xml deployment descriptor.除非由 application.xml 部署描述符指定,否则应用程序默认为 EAR 文件的基本名称,没有文件扩展名。
  • module name is the name of the module in which the bean is packaged. module name是封装 bean 的模块的名称。 In a stand-alone ejb-jar file or WAR file, the defaults to the base name of the module with any file name extension removed .在独立的 ejb-jar 文件或 WAR 文件中,默认为模块的基本名称,其中删除了任何文件扩展名 In an EAR file, the defaults to the path name of the module with any file name extension removed, but with any directory names included.在 EAR 文件中,默认为模块的路径名,删除了任何文件扩展名,但包含了任何目录名。 The default can be overridden by using the module-name element of ejb-jar.xml (for ejb-jar files) or web.xml (for WAR files).可以使用ejb-jar.xml(对于 ejb-jar 文件)或 web.xml(对于 WAR 文件)的 module-name元素来覆盖默认值

  • bean name is the ejb-name of the enterprise bean. bean name是企业 bean 的 ejb 名称。 For enterprise beans defined through annotation, the bean name defaults to the unqualified name of the session bean class, unless specified in the contents of the name() attribute of the MessageDriven annotation.对于通过注释定义的企业 bean,bean 名称默认为会话 bean 类的非限定名称,除非在 MessageDriven 注释的 name() 属性的内容中指定。 For enterprise beans defined through ejb-jar.xml, it is specified in the deployment descriptor element.对于通过 ejb-jar.xml 定义的企业 bean,它在部署描述符元素中指定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM