[英]TomEE Config Problems , jndi.properties, NameNotFoundException
as the title already shows, I am stuck with my server configuration. 正如标题已经显示的那样,我受制于服务器配置。 Goal is to have a class which will be acting as publisher and lots of subscribers to a specific topic.
目标是要有一个可以充当发布者和特定主题的大量订阅者的课程。 I am running on TomEE because the whole environment is on tomcat, and TomEE delivers the JMS API.
我在TomEE上运行,因为整个环境都在tomcat上,并且TomEE提供了JMS API。
Now to the code: 现在到代码:
javax.naming.NameNotFoundException: Name [TopicConnectionFactory] is not bound in this Context. Unable to find [TopicConnectionFactory].
that is the excpetion I get when I move to the .jsp file inside my browser which calls the method. 这是我在浏览器中调用该方法的.jsp文件时得到的称呼。
PUBLISHER: 发布者:
public void doIt(){
String _topicName = null;
Context _jndiContext = null;
TopicConnectionFactory _topicConnectionFactory=null;
TopicConnection _topicConnection = null;
TopicSession _topicSession= null;
Topic _topic = null;
TopicPublisher _topicPublisher = null;
TextMessage _textMessage = null;
_topicName = "Events";
try {
_jndiContext = new InitialContext();
_topicConnectionFactory = (TopicConnectionFactory) _jndiContext.lookup("TopicConnectionFactory");
_topic = (Topic) _jndiContext.lookup(_topicName);
_topicConnection = _topicConnectionFactory.createTopicConnection();
_topicSession = _topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
_topicPublisher = _topicSession.createPublisher(_topic);
for(int i = 0; i < 1500; i++){
_textMessage = _topicSession.createTextMessage("This i message: "+ i);
_topicPublisher.publish(_textMessage);
}
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JMSException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
if(_topicConnection != null){
try{
_topicConnection.close();
}catch(JMSException e){
e.printStackTrace();
}
}
}
}
doIt() is called inside the .jsp 在.jsp内部调用doIt()
SUBSCRIBER 订户
public static void main(String [] args){
String _topicName = null;
Context _jndiContext = null;
TopicConnectionFactory _topicConnectionFactory = null;
TopicConnection _topicConnection = null;
TopicSession _topicSession = null;
Topic _topic = null;
TopicSubscriber _topicSubscriber = null;
TextListener _topicListener = null;
TextMessage _textMessage = null;
_topicName = "Events";
try {
_jndiContext = new InitialContext();
_topicConnectionFactory =(TopicConnectionFactory) _jndiContext.lookup("TopicConnectionFactory");
_topic = (Topic) _jndiContext.lookup(_topicName);
_topicConnection = _topicConnectionFactory.createTopicConnection();
_topicSession = _topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
_topicSubscriber = _topicSession.createSubscriber(_topic);
_topicListener = new TextListener();
_topicSubscriber.setMessageListener(_topicListener);
_topicConnection.start();
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JMSException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
if(_topicConnection != null){
try{
_topicConnection.close();
}catch(JMSException e){
e.printStackTrace();
}
}
}
}
AND last but not least the jndi.properties file which is inside src folder...so inside build path 最后但并非最不重要的是src文件夹中的jndi.properties文件...因此在构建路径中
java.naming.factory.initial = org.apache.activemq.jndi.ActiveMQInitialContextFactory
java.naming.provider.url = tcp://localhost:8080
connectionFactoryNames = ConnectionFactory, queueConnectionFactory, TopicConnectionFactory
queue.MyQueue = example.MyQueue
topic.MyTopic = Events
This is copied because I have absolutely no idea how to accomplish this lookup mechanism. 复制该副本是因为我完全不知道如何完成此查找机制。 If you see anything wrong, please, correct it accordingly!
如果发现任何错误,请相应地更正!
如果您在tomee.xml
定义了TopicConnectionFactory,则可能使用以下名称: openejb:Resource/TopicConnectionFactory
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.