Question

I could send messages to Queue('test.queue') with the producer(Also i could recieve the same at the other end) But i could not recieve reply msg from reply destination('confirm') with the consumer.receive() method. No error.but consumer does not recieve any msg.Please get me out of it. Code has been given below:-

    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());
        }
    }
}
Was it helpful?

Solution

Im not a activeMQ specialist but I know in most JMS implementations (which I think NMS pretty much follows 1:1) you need to call Start() on your connection to allow consuming to begin

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top