2

I am using 2 Wildfly 11 server instances in standalone mode started with standalone-full-ha.xml.

Now i would like to send JMS Messages between those two by implementing a Sender and a Receiver that uses the same topic like this:

Receiver:

@Named
@MessageDriven(
   name="TaskJmsMsgReceiver", 
   activationConfig={
     @javax.ejb.ActivationConfigProperty(propertyName="destinationLookup", propertyValue="topic/Blubb"),
     @javax.ejb.ActivationConfigProperty(propertyName="destinationType",   propertyValue="javax.jms.Topic"),
     @javax.ejb.ActivationConfigProperty(propertyName="acknowledgeMode",   propertyValue="Auto-acknowledge")
})
public class TaskJmsMsgReceiver implements MessageListener {

    @Inject
    private TaskWebSocketChannel webSocketChannel;

    @Override
    public void onMessage(Message rcvMessage) {
        TextMessage msg = null;
        try {
            if (rcvMessage instanceof TextMessage) {
                msg = (TextMessage) rcvMessage;
                String jmsMessageText = msg.getText();
                log.info("Received JMS Message: " + jmsMessageText);
                String socketChannelEmpfaenger = jmsMessageText;
                webSocketChannel.send(socketChannelEmpfaenger);
            }
        } catch (JMSException e) {
        ...
        }
    }

}

Sender:

@JMSDestinationDefinitions({
@javax.jms.JMSDestinationDefinition(
    name = "java:/jms/topic/Blubb",
    interfaceName = "javax.jms.Topic", 
    destinationName = "Blubb")
})
@Stateless
@Dependent
public class TaskJmsMsgSender {

    @Resource(lookup = "java:/jms/topic/Blubb")
    private Topic topic;

    @Inject
    private JMSContext context;

    public void send(String text) {
        log.info("Send JMS Message: " + text);
        context.createProducer().send(topic, text);
    }

}

Now, obviously I need to configure the Wildfly instances to work together with the same JMS topic.

Can someone pls point me in the right direction how to configure this?

Thanx a lot.

Thomas
  • 620
  • 7
  • 19
  • Now i understand that i need to learn more about JGroups and the various Network Protocols that WildFly uses to discover and connect the Cluster. Seems that I have an issue there. – Thomas May 13 '18 at 14:40

2 Answers2

0

By default the standalone-full-ha.xml enables clustering for the embedded instance of Apache ActiveMQ Artemis. Therefore, if the producer is sending to one server and the consumer is running on the other server the message should flow between the servers so that the consumer will automatically receive the sent message even though they are operating on different servers.

Justin Bertram
  • 29,372
  • 4
  • 21
  • 43
0

i am using wildfly server and JMS client and its working fine. try this code it will help ful to you,

standalone.xml

 <mdb>
                <resource-adapter-ref resource-adapter-name="${ejb.resource-adapter-name:activemq-ra.rar}"/>
                <bean-instance-pool-ref pool-name="mdb-strict-max-pool"/>

 <subsystem xmlns="urn:jboss:domain:messaging-activemq:2.0">
            <server name="default">
                <security-setting name="#">
                    <role name="guest" 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>
                <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="DeckQueue" entries="java:/jboss/exported/jms/queue/DeckQueue"/>
                <connection-factory name="InVmConnectionFactory" entries="java:/ConnectionFactory" connectors="in-vm"/>
                <connection-factory name="RemoteConnectionFactory" entries="java:jboss/exported/jms/RemoteConnectionFactory" connectors="http-connector"/>
                <pooled-connection-factory name="activemq-ra" entries="java:/JmsXA java:jboss/DefaultJMSConnectionFactory" connectors="in-vm" transaction="xa"/>
            </server>

java constant

public static final String DESTINATION = "destination";
    public static final String DESTINATION_VALUE = "java:/jboss/exported/jms/queue/DeckQueue";
    public static final String DESTINATION_TYPE = "destinationType";
    public static final String DESTINATION_TYPE_VALUE = "javax.jms.Queue";
public static final String QUEUE_LOOKUP = "java:/jboss/exported/jms/queue/DeckQueue";
    public static final String CONNECTION_FACTORY = "java:jboss/DefaultJMSConnectionFactory";//

 public static boolean sendJmsMessage(Serializable obj) {
        QueueConnection connection = null;
        QueueSession session = null;

        try {
            connection = JmsConnectionFactory.getFactory().createQueueConnection();
            session = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);

            Queue queue = (Queue) JmsConnectionFactory.getContext().lookup(Constants.QUEUE_LOOKUP);
            QueueSender sender = session.createSender(queue);

            ObjectMessage objMsg = session.createObjectMessage();
            objMsg.setObject(obj);

            logger.log(Level.INFO, "Sending message : {0}", obj);

            sender.send(objMsg);

@MessageDriven(activationConfig = {
            @ActivationConfigProperty(
            propertyName = DESTINATION_TYPE, propertyValue = DESTINATION_TYPE_VALUE),
    @ActivationConfigProperty(
                    propertyName = DESTINATION, propertyValue = DESTINATION_VALUE)})
public class JmsMessageBean implements MessageListener {
chandrakant
  • 370
  • 3
  • 25