pmeyer
pmeyer

Reputation: 890

How to use MaxReconnectAttemps in ActiveMQ

I'm having an issue with ActiveMQ, I'm trying to connect using MaxReconnectAttemps but its seems to ignore the property. I'm putting an invalid destination so it tries to connect twice but it seems to be trying to connect indefinitely.

Any ideas as to set it up?

Thanks,

IConnectionFactory factory = new ConnectionFactory(("failover://(tcp://localhost:61616)?initialReconnectDelay=2000&maxReconnectAttempts=2"));
    using (Connection connection = factory.CreateConnection(username,password) as Connection)
    {
        connection.ClientId = "ClientId"; 
        using (ISession session = connection.CreateSession())
        {
            IQueue queue = session.GetQueue(queueName);
            var producer = session.CreateProducer(queue);
            producer.DeliveryMode = MsgDeliveryMode.Persistent;
            ITextMessage request = session.CreateTextMessage("Hello World!");
            producer.Send(request);
        }
    } 

Upvotes: 3

Views: 2102

Answers (1)

Tim Bish
Tim Bish

Reputation: 18401

Since you are using the .NET client you need to use a prefix on the URI options for the failover transport, so to configure maxReconnectAttempts you need to pass the option like this:

failover:(tcp://localhost:61616)?transport.maxReconnectAttempts=3

It's a good idea to look at the documentation for the client you are using which is here.

Upvotes: 3

Related Questions