I don't think callTimeout is going to help in this situation. This is
really for how long the client should wait for a response from the broker
when sending a core protocol packet which requires the connection to be
established already.

My guess is that the behavior you're seeing where the first failure takes
longer than subsequent failures is due to the OS caching the DNS lookup
failure or something like that down in the network stack.

In any case, I think you should try the "connect-timeout-millis" URL
parameter (defaults to -1), e.g.:

   tcp://host:61616?connect-timeout-millis=100

Generally speaking I'd recommend avoiding the use of
implementation-specific classes like ActiveMQConnectionFactory when
possible as it reduces the portability of your application. It's best to
stick with the pure JMS API if you can.

If you still have issues with timeouts try to grab a thread dump during the
delay so we can see exactly where the client is waiting.


Justin

On Tue, Sep 26, 2023 at 3:06 PM Westpfal, Thomas <
thomas.westpf...@saabinc.com> wrote:

> I am using the ActiveMQConnectionFactory and it appears that the factory
> blocks when creating a connection if the configured host can't be reached.
> I would like the initial connection to timeout after a set period but I
> can't seem to get the timeout to work. I have configured 0 reconnect
> attempts as I am only currently interested in the initial connection. I set
> ".setCallTimeout(100)", which if I understand correctly should timeout
> after 100ms, however this doesn't happen. I read through the documentation
> but I couldn't find any other properties I could set to configure the
> timeout. Is there such a property? And how do I timeout this initial
> connection attempt?
>
> I started by starting a Artemis docker container and ran my application
> which was able to successfully, and immediately, establish the connection.
> I verified this via the Artemis admin console. I then stopped my
> application and the docker container. I then started only my application,
> but not the container. My application appears to hang for around 36 seconds
> before finally continuing on. If I then stop my application and start my
> application again (with the docker container still stopped) I then hangs
> for only around 7 seconds before continuing on. Any subsequent restart of
> my application hangs for between 4 and 7 seconds usually. Each of these
> times I am restarting my entire application not just trying a new
> connection attempt from an existing ActiveMQConnectionFactory.
>
> I find this to be very odd that the amount of time it hangs changes. I
> would think each run of the application should reproduce similar results
> every time when the container is stopped. It could be due to how docker
> handles connections, but this is beating around the bush. The
> "setCallTimeout" I set to 100 should have timed out after 100ms regardless
> of what else was going in the background. So it is confusing to me why the
> connection is waiting for 36 seconds before continuing. I have determined
> that the wait is caused by this line:
> "activeMQConnectionFactory.createConnection();". Could you please tell me
> what is going on here, or if I simply configured the wrong property?
>
> Thanks,
> Tom
>
>
> This message is marked Public.
>
> This e-mail (including attachments) contains contents owned by Saab Group
> AB and/or its subsidiaries, affiliated companies or customers and covered
> by the laws of Sweden, the US, or Canada (federal, state or provincial).
> The information is intended to be confidential and may be legally
> privileged. If you are not the intended recipient, you are hereby notified
> that any retention, dissemination, distribution, interception or copying of
> this communication is strictly prohibited and may subject you to further
> legal action. Reply to the sender if you received this email by accident,
> and then delete the email and any attachments.
>

Reply via email to