问题
unfortunately while trying to get a JMS service working with HornetQ, I am running form error message to error message. The prior error was related to a missing core.jar file. Prior Error
After all, I am trying to implement a simple producer/consumer example as a jms service. (Based on "HornetQ Messaging Developer's Guide")
package chapter01;
import javax.jms.JMSException;
import javax.naming.NamingException;
public class ECGMessageConsumerProducerExample {
public static void main(String[] args) throws NamingException, JMSException {
// TODO Auto-generated method stub
javax.naming.Context ic = null;
javax.jms.ConnectionFactory cf = null;
javax.jms.Connection connection = null;
javax.jms.Queue queue = null;
javax.jms.Session session = null;
com.mongodb.Mongo m;
com.mongodb.DB db;
String destinationName = "queue/DLQ";
java.util.Properties p = new java.util.Properties();
p.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
p.put(javax.naming.Context.URL_PKG_PREFIXES,
"org.jboss.naming:org.jnp.interfaces");
p.put(javax.naming.Context.PROVIDER_URL, "jnp://localhost:1099");
ic = new javax.naming.InitialContext(p);
cf = (javax.jms.ConnectionFactory)ic.lookup("/ConnectionFactory");
queue = (javax.jms.Queue)ic.lookup(destinationName);
connection = cf.createConnection();
session = connection.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);
connection.start();
String theECG = "1;02/20/2012 14:01:59.010;1020,1021,1022";
javax.jms.MessageProducer publisher = session.createProducer(queue);
javax.jms.TextMessage message =
session.createTextMessage(theECG);
publisher.send(message);
System.out.println("Message sent!");
publisher.close();
}
}
While facing erros I probably added unneeded jars:
However, I get the following error message:
Exception in thread "main" java.lang.NoSuchMethodError: org.hornetq.api.core.client.ClientSessionFactory.copy()Lorg/hornetq/api/core/client/ClientSessionFactory;
at org.hornetq.jms.client.HornetQConnectionFactory.createConnectionInternal(HornetQConnectionFactory.java:612)
at org.hornetq.jms.client.HornetQConnectionFactory.createConnection(HornetQConnectionFactory.java:116)
at org.hornetq.jms.client.HornetQConnectionFactory.createConnection(HornetQConnectionFactory.java:111)
at chapter01.ECGMessageConsumerProducerExample.main(ECGMessageConsumerProducerExample.java:33)
I expect the error to be caused by a mismatch between jars used by the server and used by the client. But since I am a programmer noob, I do not really know what exact jars with suitable versions are needed.
回答1:
Try defining NettyConnectorFactory as connector as in jboss reference.
for example in hornetq-configuration.xml file:
<connectors>
<connector name="netty">
<factory-class>
org.hornetq.core.remoting.impl.netty.NettyConnectorFactory
</factory-class>
<param key="port" value="5446"/>
</connector>
</connectors>
来源:https://stackoverflow.com/questions/45214217/hornetq-jms-java-lang-nosuchmethoderror