连接C&x2B+;到ActiveMQ代理 我尝试用C++和java在JMS上开发应用。 我在java中有一个代理,它是C++的,我想用C++Publisher/ListNe/P>
我该怎么做? 我在Java上的课程有: “服务器”:连接C&x2B+;到ActiveMQ代理 我尝试用C++和java在JMS上开发应用。 我在java中有一个代理,它是C++的,我想用C++Publisher/ListNe/P>,java,c++,activemq,activemq-cpp,Java,C++,Activemq,Activemq Cpp,我该怎么做? 我在Java上的课程有: “服务器”: public class Queue { private static ActiveMQConnectionFactory connectionFactory; private static Destination destination; private static boolean transacted = false; private static Session session; private static Connection
public class Queue {
private static ActiveMQConnectionFactory connectionFactory;
private static Destination destination;
private static boolean transacted = false;
private static Session session;
private static Connection connection;
public static void main(String[] args) throws Exception {
BrokerService broker = new BrokerService();
broker.setUseJmx(true);
broker.addConnector("tcp://localhost:61616");
broker.start();
Producer p=new Producer();
Consumer c= new Consumer();
connectionFactory = new ActiveMQConnectionFactory(
ActiveMQConnection.DEFAULT_USER,
ActiveMQConnection.DEFAULT_PASSWORD,
ActiveMQConnection.DEFAULT_BROKER_URL);
connection = connectionFactory.createConnection();
connection.start();
session = connection
.createSession(transacted, Session.AUTO_ACKNOWLEDGE);
destination = session.createQueue("queue");
c.createConsumerAndReceiveAMessage(connection, connectionFactory,session,destination );
p.createProducerAndSendAMessage(destination,session);
broker.stop();
}
制作人
public class Producer {
void createProducerAndSendAMessage(Destination destination,
Session session) throws JMSException {
MessageProducer producer = session.createProducer(destination);
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
Scanner sc=new Scanner(System.in);
String msg;
while(!(msg=sc.nextLine()).equals("exit") ){
TextMessage message = session.createTextMessage(msg);
System.out.println("Sending message " + message.getText());
producer.send(message);
}
}
消费者:
public class Consumer {
public void createConsumerAndReceiveAMessage(Connection connection,
ActiveMQConnectionFactory connectionFactory, Session session,
Destination destination) throws JMSException, InterruptedException {
connection = connectionFactory.createConnection();
connection.start();
MessageConsumer consumer = session.createConsumer(destination);
MyConsumer myConsumer = new MyConsumer();
connection.setExceptionListener(myConsumer);
consumer.setMessageListener(myConsumer);
}
private static class MyConsumer implements MessageListener,
ExceptionListener {
synchronized public void onException(JMSException ex) {
System.out.println("JMS Exception occured. Shutting down client.");
System.exit(1);
}
public void onMessage(Message message) {
if (message instanceof TextMessage) {
TextMessage textMessage = (TextMessage) message;
try {
System.out.println("Received message "
+ textMessage.getText());
} catch (JMSException ex) {
System.out.println("Error reading message " + ex);
}
} else {
System.out.println("Received " + message);
}
}
}
问候你看了吗?这是ActuMeqC++客户端,在项目的主页上有文档、示例和教程。我已经看过了,但是我不能编译可下载的库。你没有提到你试过什么。你发布的Java代码是无关的,如何发布C++代码和编译时出错?当我编译时,C++中的主文件不解决依赖关系,比如< java > <代码>。但当我用make file编译activeMQ cpp的默认示例时,他编译得非常完美。