我有一个正在运行的GlassFish-Server(版本4.1)。现在我有兴趣使用jms和独立的消息传递客户端创建一个简单的消息传递服务。 (这应该在一个单独的JVM中的远程机器上运行。)不幸的是,当我尝试初始化QueueConnectionFactory时,我仍然得到一个NameNotFoundException。
这是我的代码:
import java.util.Properties;
import javax.naming.InitialContext;
import javax.jms.*;
import javax.naming.Context;
public class TestJMSQueue {
public static void main(String[] args) throws Exception{
String msg = "Hello from remote JMS Client";
test.sendMessage2Queue(msg);
System.exit(0);
}
private void sendMessage2Queue(String msg) throws Exception {
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
props.put(Context.PROVIDER_URL, "mq://localhost:7676");
props.put("connectionFactoryNames" , "TestQueueConnectionFactory");
props.put("queue." + "TestQueue", "TestQueue");
InitialContext ctx = new InitialContext(props);
System.out.println("Context created");
ConnectionFactory qFactory = (ConnectionFactory) ctx.lookup("TestQueueConnectionFactory");
Connection connection = qFactory.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
TextMessage message = session.createTextMessage();
message.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
message.setText(msg);
Queue queue = (Queue) ctx.lookup("TestQueue");
MessageProducer mp = session.createProducer(queue);
mp.send(message);
System.out.println("Message sent: " + msg);
mp.close();
session.close();
ctx.close();
}
}
服务器上存在Factory和Queue。
我关注this tutorial并已经为服务器创建了监听器。 我花了最后几个小时查看各种资源,试图解决问题,但我找不到解决方案。
你能告诉我哪里出错了吗?
非常感谢。
以下是我一直在寻找的一些资源:
修改
我还尝试使用jndi.properties文件而不是props.put(...)和InitialContext(props)。并且在InitialContext实例化之前添加以下内容:
properties.put("org.omg.CORBA.ORBInitialHost", "<IP>");
properties.put("org.omg.CORBA.ORBInitialPort", "3700");
//as found [here...][2]
//But as I understand it the solution with 3700 is not for JMS so I also tried it with 7676
也没用。
错误:
Exception in thread "main" javax.jms.JMSException: Could not create Transport. Reason: java.io.IOException: Transport scheme NOT recognized: [mq]
at org.apache.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:33)
at org.apache.activemq.ActiveMQConnectionFactory.createTransport(ActiveMQConnectionFactory.java:232)
at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:245)
at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:214)
at org.apache.activemq.ActiveMQConnectionFactory.createConnection(ActiveMQConnectionFactory.java:161)
at testjmsqueue.TestJMSQueue.sendMessage2Queue(TestJMSQueue.java:60)
at testjmsqueue.TestJMSQueue.main(TestJMSQueue.java:30)
Caused by: java.io.IOException: Transport scheme NOT recognized: [mq]
at org.apache.activemq.util.IOExceptionSupport.create(IOExceptionSupport.java:25)
at org.apache.activemq.transport.TransportFactory.findTransportFactory(TransportFactory.java:171)
at org.apache.activemq.transport.TransportFactory.connect(TransportFactory.java:76)
at org.apache.activemq.ActiveMQConnectionFactory.createTransport(ActiveMQConnectionFactory.java:230)
... 5 more
Caused by: java.io.IOException: Could not find factory class for resource: META-INF/services/org/apache/activemq/transport/mq
at org.apache.activemq.util.FactoryFinder.doFindFactoryProperies(FactoryFinder.java:90)
at org.apache.activemq.util.FactoryFinder.newInstance(FactoryFinder.java:58)
at org.apache.activemq.util.FactoryFinder.newInstance(FactoryFinder.java:47)
at org.apache.activemq.transport.TransportFactory.findTransportFactory(TransportFactory.java:167)
... 7 more
答案 0 :(得分:1)
试
/* It seems that your windows lies on [-1,1][-1,1] square. */
/* dimension of squares: {width, height}
here rectangle since width is equal to height
The two rectangles have the same dimension.
*/
float dim[2] = {0.25f, 0.25f};
/* position of the rectangle centers, here you can see that the first is above
this array must be read like {{x1, y1}, {x2, y2}}
*/
float pos[2][2] = {{0.0f, 0.4f},{0.0f, -0.4f}};
glBegin(GL_QUADS);
glColor3f(0.5f, 0.5f, 0.5f);
glVertex2f(pos[0][0] - dim[0], pos[0][1] - dim[1]);
glVertex2f(pos[0][0] + dim[0], pos[0][1] - dim[1]);
glVertex2f(pos[0][0] + dim[0], pos[0][1] + dim[1]);
glVertex2f(pos[0][0] - dim[0], pos[0][1] + dim[1]);
glColor3f(0.5f, 0.5f, 0.5f);
glVertex2f(pos[1][0] - dim[0], pos[1][1] - dim[1]);
glVertex2f(pos[1][0] + dim[0], pos[1][1] - dim[1]);
glVertex2f(pos[1][0] + dim[0], pos[1][1] + dim[1]);
glVertex2f(pos[1][0] - dim[0], pos[1][1] + dim[1]);
glEnd();