From dd7c66cfa4f05b77d34b3e3ea04f0c0cef2cb761 Mon Sep 17 00:00:00 2001 From: George Gastaldi Date: Fri, 26 Jul 2024 09:32:22 -0300 Subject: [PATCH] Repeat NettyConnectorFactory for each host Co-authored-by: Marco Bungart <32584495+turing85@users.noreply.github.com> --- .../jms/ra/ArtemisResourceAdapterFactory.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/ra/runtime/src/main/java/io/quarkus/artemis/jms/ra/ArtemisResourceAdapterFactory.java b/ra/runtime/src/main/java/io/quarkus/artemis/jms/ra/ArtemisResourceAdapterFactory.java index 4360a727..c121b015 100644 --- a/ra/runtime/src/main/java/io/quarkus/artemis/jms/ra/ArtemisResourceAdapterFactory.java +++ b/ra/runtime/src/main/java/io/quarkus/artemis/jms/ra/ArtemisResourceAdapterFactory.java @@ -1,6 +1,8 @@ package io.quarkus.artemis.jms.ra; import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.IntStream; import jakarta.jms.ConnectionFactory; import jakarta.jms.Message; @@ -43,8 +45,14 @@ public String getProductVersion() { @Override public ActiveMQResourceAdapter createResourceAdapter(String id, Map config) { ActiveMQResourceAdapter adapter = new ActiveMQResourceAdapter(); - adapter.setConnectorClassName(NettyConnectorFactory.class.getName()); - adapter.setConnectionParameters(config.get("connection-parameters")); + String connectionParameters = config.get("connection-parameters"); + int hosts = Math.max(1, count(connectionParameters, "host=")); + // Repeat the NettyConnectorFactory class name for each host + String connectorClassName = NettyConnectorFactory.class.getName(); + adapter.setConnectorClassName(IntStream.rangeClosed(1, hosts) + .mapToObj(unused -> connectorClassName) + .collect(Collectors.joining(","))); + adapter.setConnectionParameters(connectionParameters); adapter.setProtocolManagerFactoryStr(config.get("protocol-manager-factory")); adapter.setUseJNDI(false); adapter.setUserName(config.get("user")); @@ -86,6 +94,15 @@ public MessageEndpoint wrap(MessageEndpoint endpoint, Object resourceEndpoint) { return new JMSMessageEndpoint(endpoint, (MessageListener) resourceEndpoint); } + private static int count(String text, String find) { + int count = 0; + final int length = find.length(); + for (int index = 0; (index = text.indexOf(find, index)) != -1; index += length) { + count++; + } + return count; + } + private static class JMSMessageEndpoint extends MessageEndpointWrapper implements MessageListener { private final MessageListener listener;