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.