英文:
Unable to bind JMS resources with Openliberty
问题
以下是您要翻译的内容:
我正在使用OpenLiberty上的Jakarta Messaging迈出第一步。一个简单的发送方和接收方"test"。但是我在绑定JNDI资源方面遇到了困难。
这是我的 server.xml
配置:
...
<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>
...
这是我的发送方
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();
}
}
}
然而,connection = connectionFactory.createConnection();
这一行会抛出一个空指针异常。我尝试过 打印JNDI绑定,但JMS相关的内容都不见了。
对于我做错了什么有任何想法吗?
编辑:
根据@Gas的提示,添加了 messagingServer-3.0
和 messagingClient-3.0
功能解决了问题,JMS组件出现在JNDI中。
英文:
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.
答案1
得分: 2
因为 @Gas 的提示,添加以下内容解决了问题,并且 JMS 组件出现在 JNDI 中:
...
<feature>messagingServer-3.0</feature>
<feature>messagingClient-3.0</feature>
...
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论