Skip to content

Commit

Permalink
Repeat NettyConnectorFactory for each host
Browse files Browse the repository at this point in the history
Co-authored-by: Marco Bungart <[email protected]>
  • Loading branch information
gastaldi and turing85 committed Jul 29, 2024
1 parent 33fdf7b commit dd7c66c
Showing 1 changed file with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -43,8 +45,14 @@ public String getProductVersion() {
@Override
public ActiveMQResourceAdapter createResourceAdapter(String id, Map<String, String> 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"));
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit dd7c66c

Please sign in to comment.