2

i will configure two wildfly-swarm (Version 2018.5.0) server remote. The first server should send messages (over wildfly-swarm messaging) to the second server. On the second server a consumer for messaging is running.

After reading a lot of (outdated) tutorials, i come to the conclusion that i'm to stupid.

I build a test project with wildfly-swarm messaging in one server.

project-default.yaml

swarm:
  messaging-activemq:
    servers:
      default:
        jms-queues:
          my-queue: {}
        jms-topics:
          my-topic: {}
  logging:
      pattern-formatters:
        LOG_FORMATTER:
          pattern: "%p [%c] %s%e%n"
      periodic-rotating-file-handlers:
        FILE:
          file:
            path: pathtolog/swarm.log
          suffix: .yyyy-MM-dd
          named-formatter: LOG_FORMATTER
          level: ALL
      root-logger:
        handlers:
        - FILE

MyApplication.java

import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;

@ApplicationPath("/")
public class MyApplication extends Application
{
}

MyResource.java

import javax.annotation.Resource;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.jms.JMSContext;
import javax.jms.Topic;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import java.util.logging.Level;
import java.util.logging.Logger;


@ApplicationScoped
@Path("/")
public class MyResource
{
    Logger LOG = Logger.getLogger(MyResource.class.getName());

    public static final String MY_TOPIC = "/jms/topic/my-topic";

    @Inject
    private JMSContext context;

    @Resource(lookup = MY_TOPIC)
    private Topic topic;

    @GET
    @Produces("text/plain")
    public String get()
    {
        LOG.log(Level.INFO, "Send Message Hello JMS!");
        context.createProducer().send(topic, "Hello JMS!");
        return "send!";
    }

}

MyTopicMDB.java

import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;
import java.util.logging.Level;
import java.util.logging.Logger;


@MessageDriven(name = "MyTopicMDB", activationConfig = {
        @ActivationConfigProperty(propertyName = "destinationLookup", propertyValue = MyResource.MY_TOPIC),
        @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"),
})
public class MyTopicMDB implements MessageListener
{
    Logger LOG = Logger.getLogger(MyResource.class.getName());

    @Override
    public void onMessage(Message message)
    {
        try
        {
            LOG.log(Level.INFO, "received Message " + ((TextMessage) message).getText());
            System.out.println("received: " + ((TextMessage) message).getText());
        }
        catch (JMSException e)
        {
            LOG.log(Level.INFO, "Fehler: " + e);
            e.printStackTrace();
        }
    }
}

any idea how i must configure the project-default.yaml for the servers (one sender and one consumer)?

Andreas
  • 31
  • 4

1 Answers1

5

We had the same issue and you were nearly there: the only thing missing would be this in the project-default of the Swarm (now Thorntail) server which is going to connect to the remote messaging server:

swarm:
  network:
    socket-binding-groups:
      standard-sockets:
        outbound-socket-bindings:
          remote-activemq-socket-binding:
            remote-host: <address of remote server>
            remote-port: <port of remote server, likely going to be 61616>

  messaging-activemq:
    servers:
      default:
        [...]
        remote-connectors:
          remote-activemq-connector:
            socket-binding: remote-activemq-socket-binding
        pooled-connection-factories:
          remote-connection-factory:
            # if authentication is required
            user: <user>
            password: <password>
            connectors:
              - remote-activemq-connector
            entries:
              - 'java:/jms/remote-mq'
              - 'java:/DefaultJMSConnectionFactory'

Then on the sender side, you would inject your connection factory like this:

@Inject
@JMSConnectionFactory("java:/jms/remote-mq")
private JMSContext context;

Or, on the consumer side, you would annotate your MDB with

@ResourceAdapter("remote-connection-factory")
Dominique Toupin
  • 411
  • 3
  • 11