1

I am doing my first steps with Jakarta Messaging on OpenLiberty. A simple sender and receiver "test". But I am having troubles binding the JNDI resources.

This is my server.xml config:

...
    <featureManager>
        <feature>webProfile-9.1</feature>
        <feature>mail-2.0</feature>
        <feature>concurrent-2.0</feature>
        <feature>messaging-3.0</feature>
    </featureManager>
...
    <messagingEngine>
        <queue id="SIMPLE_QUEUE"/>
    </messagingEngine>

    <jmsQueueConnectionFactory jndiName="jms/JmsFactory">
        <properties.wasJms />
    </jmsQueueConnectionFactory>

    <jmsQueue id="jms/JmsQueue" jndiName="jms/JmsQueue">
        <properties.wasJms queueName="SIMPLE_QUEUE"/>
    </jmsQueue>

    <jmsActivationSpec id="jms/Reader">
        <properties.wasJms destinationRef="jms/JmsQueue"/>
    </jmsActivationSpec>
...

This is my sender

import jakarta.annotation.PostConstruct;
import jakarta.annotation.Resource;
import jakarta.faces.view.ViewScoped;
import jakarta.inject.Named;
import jakarta.jms.*;

import java.io.Serializable;

@Named
@ViewScoped
public class Sender implements Serializable {
    @Resource(lookup = "jms/JmsQueue")
    private Queue queue;

    @Resource(lookup = "jms/JmsFactory")
    private ConnectionFactory connectionFactory;

    private Connection connection;
    private Session session;
    private MessageProducer producer;

    @PostConstruct
    public void initialize() {
        try {
            connection = connectionFactory.createConnection();
            session = connection.createSession();
            producer = session.createProducer(queue);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void send() {
        try {
            TextMessage message = session.createTextMessage();
            message.setText("Hello world");
            producer.send(message);
        } catch (JMSException e) {
            e.printStackTrace();
        }
    }
}

However the line connection = connectionFactory.createConnection(); throws a nullpointer exception. I tried printing the JNDI bindings, but the JMS stuff is missing.

Any ideas on what I am doing wrong?

Edit:

Due to the tip from @Gas, adding <feature>messagingServer-3.0</feature> and <feature>messagingClient-3.0</feature> solved the issue and the JMS components appear in JNDI.

kanonroald
  • 41
  • 6
  • Didnt test it, but I think you are missing jms provider. In case of OpenLiberty built in one you have to add `messagingServer-3.0` to server.xml. – Gas Apr 17 '23 at 13:49
  • I tried it, but it does not work either. – kanonroald Apr 17 '23 at 14:06
  • 1
    FYI, you're allowed to post the answer to your own question on StackOverflow. (Or you could give Gas a chance to post and if you don't see anything then you could go ahead and post it.) – Scott Kurz Apr 17 '23 at 15:18
  • @kanonroald Feel free to describe the answer. My comment was just a hint ;-) – Gas Apr 17 '23 at 17:29

1 Answers1

2

Due to the tip of @Gas, adding

...
    <feature>messagingServer-3.0</feature>
    <feature>messagingClient-3.0</feature> 
...

solved the issue and the JMS components appear in JNDI.

kanonroald
  • 41
  • 6
  • If this is the correct answer please mark it as such to help other users who encounter this same issue in the future. Thanks! – Justin Bertram Apr 18 '23 at 14:50