java - 在 Thorntail 中使用 ActiveMQ 配置 JMS

标签 java jakarta-ee jms wildfly thorntail

我有一个关于在 Thorntail 上配置 JMS 的小问题。在我的开发项目中,我使用 Wildfly,但对于远程服务器,我们使用(我的团队)IBM Portal。我将本地服务器从 Wildfly 升级到 Thorntail,在我想在本地启动我的应用程序(使用 Maven)后,它崩溃了。我查看了日志,发现它给出了我的:

2019-12-04 10:49:50,957 ERROR [org.jboss.as.controller.management-operation] (main) WFLYCTL0013: Operation ("add") failed - address: (("deployment" => "myproject.war")) - failure description: {
    "WFLYCTL0412: Required services that are not installed:" => ["jboss.naming.context.java.module.myproject.env.jms.notification"],
    "WFLYCTL0180: Services with missing/unavailable dependencies" => [
        "jboss.naming.context.java.module.myproject.env.\"myproject.notifications.service.impl.JmsNotificationServiceImpl\".connectionFactory is missing [jboss.naming.context.java.module.myproject.env.jms.notification]",
        "jboss.naming.context.java.module.myproject.env.\"myproject.notifications.service.impl.JmsNotificationServiceImpl\".topic is missing [jboss.naming.context.java.module.myproject.env.jms.notification]"
    ]
}
2019-12-04 10:49:50,994 ERROR [org.jboss.as.server] (main) WFLYSRV0021: Deploy of deployment "myproject.war" was rolled back with the following failure message: 
{
    "WFLYCTL0412: Required services that are not installed:" => ["jboss.naming.context.java.module.myproject.env.jms.notification"],
    "WFLYCTL0180: Services with missing/unavailable dependencies" => [
        "jboss.naming.context.java.module.myproject.env.\"myproject.notifications.service.impl.JmsNotificationServiceImpl\".connectionFactory is missing [jboss.naming.context.java.module.myproject.env.jms.notification]",
        "jboss.naming.context.java.module.myproject.env.\"myproject.notifications.service.impl.JmsNotificationServiceImpl\".topic is missing [jboss.naming.context.java.module.myproject.env.jms.notification]"
    ]
}

在我们的本地环境中,我们没有为 JMS 目的配置任何队列,因为我们的主队列机制位于远程服务器 (IBM Portal) 上。 我们正在使用一些代码:

public class JmsNotificationServiceImpl implements JmsNotificationService {

    @Resource(lookup = "jms/notificationCF")
    private ConnectionFactory connectionFactory;

    @Resource(lookup = "jms/topic/notification")
    private Topic topic;

    @Override
    public void send(String string) throws Exception {
        Connection connection = null;
        try {
            connection = connectionFactory.createConnection();
            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            MessageProducer producer = session.createProducer(topic);

            log.info("Sending JMS message to topic...");
            producer.send(session.createObjectMessage(string));
            log.info("Message sent succesfull.");
        } catch (JMSException e) {
            throw new Exception("Error while creation or sending jms message", e);
        }
    }

}

我发现Thorntail中有ActiveMQ的构建,但我不太知道如何在ActiveMQ中配置ConnectionFactory和Topic。谁能帮我理解在哪里放置一些配置以及如何配置它?

最佳答案

Minimalistic project-defaults.yml 允许您的thorntail实例连接到远程消息代理

swarm:
  network:
    socket-binding-groups:
      standard-sockets:
        outbound-socket-bindings:
          remote-activemq-socket-binding:
            remote-host: 127.0.0.1
            remote-port: 61616
  messaging-activemq:
    servers:
      default:
        remote-connectors:
          remote-activemq-connector:
            socket-binding: remote-activemq-socket-binding
        pooled-connection-factories:
          remote-connection-factory:
            user: myuser
            password: otherpassword
            connectors:
              - remote-activemq-connector
            entries:
              - 'java:/jms/remote-mq'
              - 'java:/DefaultJMSConnectionFactory'
        jms-queues:
          session-tracking-queue:
            entries:
              entry: 'java:/jms/queue/testQueue'

需要包含以下依赖项:

<dependency>
    <groupId>io.thorntail</groupId>
    <artifactId>messaging</artifactId>
</dependency>

关于java - 在 Thorntail 中使用 ActiveMQ 配置 JMS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59176124/

相关文章:

javax.cache 自动删除条目

java - 如何在 Hibernate 中重用模型而不创建新模型

java - ActiveMQ 代理能够处理的最大主题数是多少?

java - 在运行时更新 jms 入站适配器目标

java - JMS 消息对象可以有多大?

java - 清除已插入 HashMap 的对象

java - 在 Jclouds for openstack 中创建 NeutronApi 对象时抛出 com.google.inject.ConfigurationException

java - 除了必须计算的值之外还有一个附加条件的动态规划问题

java - 更改 xml 节点中的值时出错

mysql - 当我尝试在表中保存值时出现错误 table.auto_pk_support