我将远程配置两个wildfly-swarm (2018.5.0版)服务器。第一个服务器应该向第二个服务器发送消息(通过野蝇群消息传递)。在第二台服务器上,消息传递的消费者正在运行。
在阅读了很多(过时的)教程后,我得出结论,我太愚蠢了。
我在一台服务器上使用wildfly-swarm消息构建了一个测试项目。
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:
- FILEMyApplication.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();
}
}
}你知道我必须如何为服务器(一个发送者和一个消费者)配置project-default.yaml吗?
发布于 2018-06-16 02:21:21
我们也遇到了同样的问题,而您就快到了:唯一缺少的是项目中的这个- Swarm (现在是Thorntail)服务器的默认设置,它将连接到远程消息传递服务器:
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'然后在发送方,您可以像这样注入您的连接工厂:
@Inject
@JMSConnectionFactory("java:/jms/remote-mq")
private JMSContext context;@ResourceAdapter("remote-connection-factory")https://stackoverflow.com/questions/50329148
复制相似问题