-
1. Re: Wildfly 10.x connect to a remote HornetQ standalone server
matafe Oct 2, 2016 2:11 PM (in response to matafe)1 of 1 people found this helpfulI think that I find out the solution:
On the Wildfly 10.x:
<subsystem xmlns="urn:jboss:domain:messaging-activemq:1.0">
<server name="default">
<connector name="remote-jms" factory-class="org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnectorFactory">
<param name="host" value="localhost"/>
<param name="port" value="5445"/>
</connector>
<pooled-connection-factory name="hornetq-ra" transaction="xa" protocol-manager-factory="org.apache.activemq.artemis.core.protocol.hornetq.client.HornetQClientProtocolManagerFactory" entries="java:/RemoteHornetqConnectionFactory java:jboss/DefaultJMSConnectionFactory" connectors="remote-jms"/>
</server>
</subsystem>
Notes:
The Connection Factory on remote (in my case is localhost [port: 5445]) is named: RemoteHornetqConnectionFactory
The DefaultJMSConnectionFactory is required to be here because the Java EE 7 Spec.
Now you can the a Sender:
Just a simple Example:
@Stateless
public class MessageSender {
@Resource
private ConnectionFactory connectionFactory;
public void sendMessage(String text) {
Connection connection = null;
Session session = null;
try {
connection = connectionFactory.createConnection();
connection.start();
// Create a Session
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = session.createQueue("testQueue");
// Create a MessageProducer from the Session to the Topic or Queue
MessageProducer producer = session.createProducer(queue);
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
// Create a message
TextMessage message = session.createTextMessage(text);
// Tell the producer to send the message
producer.send(message);
} catch (Exception e) {
e.printStackTrace();
} finally {
// Clean up
if (session != null)
try {
session.close();
} catch (JMSException e) {
e.printStackTrace();
}
if (connection != null)
try {
connection.close();
} catch (JMSException e) {
e.printStackTrace();
}
}
}
public String receiveMessage() {
Connection connection = null;
Session session = null;
MessageConsumer consumer = null;
try {
connection = connectionFactory.createConnection();
connection.start();
// Create a Session
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = session.createQueue("testQueue");
// Create a MessageConsumer from the Session to the Topic or Queue
consumer = session.createConsumer(queue);
// Wait for a message
TextMessage message = (TextMessage) consumer.receive(1000);
return message == null ? null : message.getText();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (consumer != null)
try {
consumer.close();
} catch (JMSException e) {
e.printStackTrace();
}
if (session != null)
try {
session.close();
} catch (JMSException e) {
e.printStackTrace();
}
if (connection != null)
try {
connection.close();
} catch (JMSException e) {
e.printStackTrace();
}
}
return null;
}
}
Regards.
-
2. Re: Wildfly 10.x connect to a remote HornetQ standalone server
m4maksud Jan 29, 2019 5:21 AM (in response to matafe)Worked fine for me! Thank you!
-
3. Re: Wildfly 10.x connect to a remote HornetQ standalone server
hali19790320 Apr 7, 2019 8:47 AM (in response to matafe)Hi!
Yes this worked, but just if hornetq is up to 2.3.0.CR1 and jboss 7.2 released with 2.3.0.CR1.
How is possible the upgrade?
Thanks.
Halcsi