jakarta-eejmswebsphere-libertyjava-ee-8jms2

JMS MessageListener not working on Liberty


I working on Liberty 18.0.0.2 with JavaEE 8 full profile .
I configured JMS 2 on server.xml with this content :

<?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 :

@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 ?
What's mistake ?
I search in google and found some examples , but can not understand how can fix this problem ! .


Solution

  • 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:

    @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:

    The ID value must be in the format of application name/module name/bean name where: