Identifier in Apache Activemq

Asked

Viewed 66 times

2

I’m trying to integrate a consumer into a queue that uses the message Broker Apache Activemq. However, to consume these queues you need to configure an identifier, user and password. I can’t set that identifier, the code I’m using is this:

    using Apache.NMS.Util;
    using System;
    using System.Threading;

 namespace Apache.NMS.ActiveMQ.Test
 {
    public class TestMain
    {
        protected static AutoResetEvent semaphore = new AutoResetEvent(false);
        protected static ITextMessage message = null;
        protected static TimeSpan receiveTimeout = TimeSpan.FromSeconds(10);

        public static void Main(string[] args)
        {
        string conexao = "tcp://IP-DA-FILA-DO-SISTEMA";
        string FILA = "FILA-DO-SISTEMA";

        string identificador = "IDENTIFICADOR-FILA-SISTEMA";

            Uri connecturi = new Uri(conexao);

            Console.WriteLine("Conectando com: " + connecturi);

            IConnectionFactory factory = new NMSConnectionFactory(connecturi);

            using (IConnection connection = factory.CreateConnection("ADMIN", "ADMIN"))
            using (ISession session = connection.CreateSession())
            {
                IDestination destination = SessionUtil.GetDestination(session, FILA);

                Console.WriteLine("Usando o destino: " + destination);

                using (IMessageConsumer consumer = session.CreateConsumer(destination))
                //using (IMessageProducer producer = session.CreateProducer(destination))
                {
                    // Iniciar a conexão que as mensagens serão processadas
                    connection.Start();

                    //producer.DeliveryMode = MsgDeliveryMode.Persistent;
                    //producer.RequestTimeout = receiveTimeout;

                    consumer.Listener += new MessageListener(OnMessage);

                    //producer.Send(request);

                    semaphore.WaitOne();
                }
            }
        }


        protected static void OnMessage(IMessage receivedMsg)
        {
            message = receivedMsg as ITextMessage;
            Console.WriteLine(message.Text);
        }
    }
}

The user, password and address of the queue are correct (not those that are in the code above), but I can’t configure this identifier that is missing.

Error message:

Apache.NMS.ActiveMQ.BrokerException: 'java.lang.Exception : Invalid consumer for username + password combination!

The error is displayed in the following line:

 using (IMessageConsumer consumer = session.CreateConsumer(destination))

Apparently the connection is made, but missing enter this identifier to be able to create the Consumer.

  • Any error messages? Did you debug the code? Where did you get this snippet of code?

  • Leandro, I edited the post. This code snippet was made available by apache at this link:https://activemq.apache.org/components/nms/examples/nms-simple-asynchronous-consumer-example

  • Aren’t you missing something in your string Connection? type activemq:tcp, as well as in the queues and Consumers declaration?

  • I tried inserting the string activemq before the tcp address and still the same error occurs. In some tests I performed, the activemq code that precedes the connection address is optional.

1 answer

0

I’m answering my own question to help people who have the same problem in the future. The error of being able to make the connection and not being able to create the consumer is a problem of permissions in message Broker. After solving this permission problem, new queue addresses were generated and it is now possible to consume the data.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.