我在standalone-full-ha.xml下以独立模式使用2个Wildfly 11服务器实例。
现在我想通过实现使用相同主题的Sender和Receiver来发送这两者之间的JMS消息:
接收器:
@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) {
...
}
}
}
发信人:
@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);
}
}
现在,显然我需要配置Wildfly实例以与同一个JMS主题一起工作。
有人可以指出我正确的方向如何配置?
Thanx很多。
答案 0 :(得分:0)
默认情况下,standalone-full-ha.xml为Apache ActiveMQ Artemis的嵌入式实例启用群集。因此,如果生产者发送到一个服务器并且消费者正在另一个服务器上运行,则消息应该在服务器之间流动,以便消费者将自动接收发送的消息,即使它们在不同的服务器上运行。
答案 1 :(得分:0)
我正在使用wildfly服务器和JMS客户端,它的工作正常。尝试这段代码对你有帮助,
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常量
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 {