2

我可以使用生产者将消息发送到队列('test.queue')(我也可以在另一端收到相同的消息)但是我无法使用消费者.receive()从回复目的地('确认')接收回复消息方法。没有错误。但消费者没有收到任何消息。请让我摆脱它。代码如下: -

    class Program
{
    private const String URI = "tcp://localhost:61616";
    private const String DESTINATION = "test.queue";
    static void Main(String[] args)
    {
        ConnectionFactory connectionFactory = new ConnectionFactory(URI);
        connectionFactory.ClientId = connectionFactory.ClientIdGenerator.GenerateId(); ;
        IMessageProducer prod;
        String s = String.Empty;
        while (s.ToLower() != "exit")
        {
            s = Console.ReadLine();
            ISession ses = connectionFactory.CreateConnection().CreateSession();
            prod = ses.CreateProducer();
            IMessage msg=ses.CreateTextMessage(s);
            NmsDestinationAccessor destinationResolver = new NmsDestinationAccessor();
            IDestination destination = destinationResolver.ResolveDestinationName(ses, DESTINATION);
            IDestination replyDestination = destinationResolver.ResolveDestinationName(ses, "confirm");
            IMessageConsumer consumer = ses.CreateConsumer(replyDestination);
            prod.Send(destination, msg);
            IMessage im= consumer.Receive();
            ses.Commit();
            Console.WriteLine(im.ToString());
        }
    }
}
4

1 回答 1

2

我不是 activeMQ 专家,但我知道在大多数 JMS 实现中(我认为 NMS 几乎遵循 1:1)你需要在你的连接上调用 Start() 以允许开始消费

于 2012-04-19T14:16:09.830 回答