JMS Bridge to external Wildfly with Active MQ Artemis not working
Hi, i have the problem, that i have to connect two wildfly server with ActiveMQ Artemis over a Bridge. In the source server, Spring should receive and send messages to the target server.
My understanding is, the source server has a source queue and the configuration for the bridge. The target server only has the target queue. In the source server, i put all messages into the source queue and the bridge will forward them to the target queue on the target server.
In my case, the source server will send the message over spring jms to the source queue. But the source queue is not found on the source server. I can only connect to the target queue of the target server directly without involving the bridge.
My configuration for the source and target server with the queues and the bridge looks as follows:
Client (source server):
<subsystem xmlns="urn:jboss:domain:messaging-activemq:10.0">
<server name="default">
<security-setting name="#">
<role name="messaging" send="true" consume="true" create-non-durable-queue="true" delete-non-durable-queue="true"/>
</security-setting>
<address-setting name="#" dead-letter-address="jms.queue.DLQ" expiry-address="jms.queue.ExpiryQueue" max-size-bytes="10485760" page-size-bytes="2097152" message-counter-history-day-limit="10"/>
<remote-connector name="bridge-connector" socket-binding="bridge"/>
<in-vm-connector name="in-vm" server-id="0">
<param name="buffer-pooling" value="false"/>
</in-vm-connector>
<in-vm-acceptor name="in-vm" server-id="0">
<param name="buffer-pooling" value="false"/>
</in-vm-acceptor>
<jms-queue name="ExpiryQueue" entries="java:/jms/queue/ExpiryQueue"/>
<jms-queue name="DLQ" entries="java:/jms/queue/DLQ"/>
<jms-queue name="HealthQueue" entries="java:/jms/queue/HealthQueue"/>
<jms-queue name="JMSSourceBridgeQueue" entries="queue/JMSSourceBridgeQueue java:jboss/exported/jms/queues/JMSSourceBridgeQueue java:/jms/queue/JMSSourceBridgeQueue"/>
<connection-factory name="InVmConnectionFactory" entries="java:/ConnectionFactory" connectors="in-vm"/>
<connection-factory name="RemoteConnectionFactory" entries="java:jboss/exported/jms/RemoteConnectionFactory" connectors="bridge-connector"/>
<pooled-connection-factory name="activemq-ra" entries="java:/JmsXA java:jboss/DefaultJMSConnectionFactory" connectors="in-vm" transaction="xa"/>
</server>
<jms-bridge name="bridge" module="org.apache.activemq.artemis" quality-of-service="AT_MOST_ONCE" failure-retry-interval="500" max-retries="1" max-batch-size="10" max-batch-time="100">
<source connection-factory="ConnectionFactory" destination="jms/queue/JMSSourceBridgeQueue">
<source-context/>
</source>
<target password="developer" user="developer" connection-factory="ConnectionFactory" destination="JMSTargetBridgeQueue">
<target-context>
<property name="java.naming.factory.initial" value="org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory"/>
<property name="java.naming.provider.url" value="tcp://localhost:5345"/>
<property name="queue.JMSTargetBridgeQueue" value="JMSTargetBridgeQueue"/>
<property name="java.naming.security.principal" value="developer"/>
<property name="java.naming.security.credentials" value="developer"/>
</target-context>
</target>
</jms-bridge>
</subsystem>
<subsystem xmlns="urn:jboss:domain:naming:2.0">
<bindings>
<external-context name="java:global/remoteContext" module="org.apache.activemq.artemis" class="javax.naming.InitialContext">
<environment>
<property name="java.naming.factory.initial" value="org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory"/>
<property name="java.naming.provider.url" value="tcp://127.0.0.1:6745"/>
<property name="queue.JMSTargetBridgeQueue" value="JMSTargetBridgeQueue"/>
<property name="java.naming.security.principal" value="developer"/>
<property name="java.naming.security.credentials" value="developer"/>
</environment>
</external-context>
<lookup name="JMSTargetBridgeQueue" lookup="java:global/remoteContext/JMSTargetBridgeQueue"/>
</bindings>
<remote-naming/>
</subsystem>
<outbound-socket-binding name="bridge">
<remote-destination host="${socket.binding.jboss.bridge.port:127.0.0.1}" port="${socket.binding.jboss.bridge.port:5345}"/>
</outbound-socket-binding>
Server (target server):
<subsystem xmlns="urn:jboss:domain:messaging-activemq:10.0">
<server name="default">
<security-setting name="#">
<role name="messaging" send="true" consume="true" create-non-durable-queue="true" delete-non-durable-queue="true"/>
</security-setting>
<address-setting name="#" dead-letter-address="jms.queue.DLQ" expiry-address="jms.queue.ExpiryQueue" max-size-bytes="10485760" page-size-bytes="2097152" message-counter-history-day-limit="10"/>
<http-connector name="http-connector" socket-binding="http" endpoint="http-acceptor"/>
<http-connector name="http-connector-throughput" socket-binding="http" endpoint="http-acceptor-throughput">
<param name="batch-delay" value="50"/>
</http-connector>
<in-vm-connector name="in-vm" server-id="0">
<param name="buffer-pooling" value="false"/>
</in-vm-connector>
<http-acceptor name="http-acceptor" http-listener="default"/>
<http-acceptor name="http-acceptor-throughput" http-listener="default">
<param name="batch-delay" value="50"/>
<param name="direct-deliver" value="false"/>
</http-acceptor>
<remote-acceptor name="bridge-acceptor" socket-binding="bridge"/>
<in-vm-acceptor name="in-vm" server-id="0">
<param name="buffer-pooling" value="false"/>
</in-vm-acceptor>
<jms-queue name="ExpiryQueue" entries="java:/jms/queue/ExpiryQueue"/>
<jms-queue name="DLQ" entries="java:/jms/queue/DLQ"/>
<jms-queue name="VaultQueue" entries="java:/jms/queue/VaultQueue"/>
<jms-queue name="DmsQueue" entries="java:/jms/queue/DmsQueue"/>
<jms-queue name="JMSTargetBridgeQueue" entries="queue/JMSTargetBridgeQueue java:jboss/exported/jms/queue/JMSTargetBridgeQueue java:jboss/jms/queue/JMSTargetBridgeQueue"/>
<connection-factory name="InVmConnectionFactory" entries="java:/ConnectionFactory" connectors="in-vm"/>
<pooled-connection-factory name="activemq-ra" entries="java:/JmsXA java:jboss/DefaultJMSConnectionFactory" connectors="in-vm" transaction="xa"/>
</server>
</subsystem>
<socket-binding name="bridge" port="${socket.binding.jboss.bridge.port:5345}"/>
Spring Properties
spring:
artemis:
mode: native
host: localhost
port: 5345
user: developer
password: developer
Configuration
@Configuration
@EnableJms
@ImportAutoConfiguration({ ArtemisAutoConfiguration.class })
@EnableConfigurationProperties({ ArtemisProperties.class })
public class ActiveMQConfig {
@Bean
public JmsTemplate jmsTemplate(ConnectionFactory connectionFactory, MessageConverter messageConverter) {
JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory);
jmsTemplate.setMessageConverter(messageConverter);
return jmsTemplate;
}
@Bean
public MessageConverter messageConverter() {
MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
converter.setTargetType(MessageType.TEXT);
converter.setTypeIdPropertyName("_type");
return converter;
}
@Bean
public ConnectionFactory connectionFactory(ArtemisProperties artemisProperties) {
final ActiveMQConnectionFactory activeMQConnectionFactory = ActiveMQJMSClient.createConnectionFactoryWithHA(
JMSFactoryType.CF, transportConfiguration(artemisProperties.getHost(), artemisProperties.getPort()));
activeMQConnectionFactory.setUser(artemisProperties.getUser());
activeMQConnectionFactory.setPassword(artemisProperties.getPassword());
return activeMQConnectionFactory;
}
private TransportConfiguration transportConfiguration(String host, int port) {
final Map<String, Object> params = new HashMap<>();
params.put(TransportConstants.HOST_PROP_NAME, host);
params.put(TransportConstants.PORT_PROP_NAME, port);
return new TransportConfiguration(NettyConnectorFactory.class.getName(), params);
}
}
if i want to send a message
public void handleReply(ResponseKeyExchangeMessage responseKeyExchangeMessage) {
log.info("Sending message to queue {}.", keyStoreBridge);
log.debug("Sending message {} to remote.",
ToStringBuilder.reflectionToString(responseKeyExchangeMessage, ToStringStyle.JSON_STYLE));
jmsTemplate.convertAndSend("JMSSourceBridgeQueue", responseKeyExchangeMessage);
}
i get this error
Caused by: javax.jms.JMSException: There is no queue with name JMSSourceBridgeQueue
at org.apache.activemq.artemis.jms.client.ActiveMQSession.internalCreateQueue(ActiveMQSession.java:500)
at org.apache.activemq.artemis.jms.client.ActiveMQSession.createQueue(ActiveMQSession.java:479)
at org.springframework.jms.support.destination.DynamicDestinationResolver.resolveQueue(DynamicDestinationResolver.java:85)
at org.springframework.jms.support.destination.DynamicDestinationResolver.resolveDestinationName(DynamicDestinationResolver.java:59)
at org.springframework.jms.support.destination.JmsDestinationAccessor.resolveDestinationName(JmsDestinationAccessor.java:115)
at org.springframework.jms.core.JmsTemplate.lambda$send$3(JmsTemplate.java:585)
at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:504)
I have found this issue
https://access.redhat.com/discussions/5209151
but this does not solve my problem.
I am running out of ideas. I dont know what i am doing wrong or what is missing. Hope somebody can help me.
Doesnt this work on the same host?