首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用向ActiveMQ Artemis主题发送消息

用向ActiveMQ Artemis主题发送消息
EN

Stack Overflow用户
提问于 2018-06-14 09:23:54
回答 1查看 2.1K关注 0票数 3

目标

我想向一个主题发送一条信息,稍后我将处理一个客户端应用程序。为此,我使用Spring和及其JMS模块。作为消息代理,我使用本机ActiveMQ Artemis。

,这是我的设置

DemoApplication.java

代码语言:javascript
复制
@SpringBootApplication
public class DemoApplication {

    private static final Logger logger = LoggerFactory.getLogger(DemoApplication.class);

    public interface StarGate {
        void sendHello(String helloText);
    }

    @Autowired
    private ConnectionFactory connectionFactory;

    @Bean
    public IntegrationFlow mainFlow() {
        return IntegrationFlows
                .from(StarGate.class)
                .handle(Jms.outboundAdapter(connectionFactory)
                        .configureJmsTemplate(jmsTemplateSpec -> jmsTemplateSpec
                                .deliveryPersistent(true)
                                .pubSubDomain(true)
                                .sessionTransacted(true)
                                .sessionAcknowledgeMode(Session.CLIENT_ACKNOWLEDGE)
                                .explicitQosEnabled(true)
                        )
                        .destination(new ActiveMQTopic("wormhole")))
                .get();
    }

    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(DemoApplication.class, args);
        StarGate stargate = context.getBean(StarGate.class);
        stargate.sendHello("Jaffa, kree!");
        logger.info("Hello message sent.");
    }

}

application.properties

代码语言:javascript
复制
spring.artemis.mode=native
spring.artemis.host=localhost
spring.artemis.port=61616
spring.artemis.user=artemis
spring.artemis.password=simetraehcapa

spring.jms.pub-sub-domain=true
spring.jms.template.delivery-mode=persistent
spring.jms.template.qos-enabled=true
spring.jms.listener.acknowledge-mode=client

logging.level.org.springframework=INFO

build.gradle (重要部分)

代码语言:javascript
复制
springBootVersion = '2.0.2.RELEASE'
dependencies {
    compile('org.springframework.boot:spring-boot-starter-artemis')
    compile('org.springframework.boot:spring-boot-starter-integration')
    compile('org.springframework.integration:spring-integration-jms')
    testCompile('org.springframework.boot:spring-boot-starter-test')
}

作为一个ActiveMQ Artemis服务器,我使用了带有默认配置的vromero/artemis (2.6.0)码头映像。

问题

在生产者端,消息似乎是成功地发送了,但是在消息broker端,消息缺少。创建了地址,但缺少队列。

将来主题的名称将是动态的,因此不允许我在broker.xml中手动创建主题。我依赖于Artemis的自动队列创建功能。

为什么在这种情况下消息发送不起作用?

Nerd注意:,我知道星门基本上是以点对点的方式通过虫洞连接的,但是为了这个问题,让我们忽略这个事实。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-06-14 13:57:29

当一条消息被发送到某个主题,并且对地址和队列都启用自动创建时,只有地址才会被创建,而不是队列。如果队列被自动创建并将消息放入队列中,则会违反主题的语义。只有响应订阅服务器才会创建主题地址上的订阅队列。因此,在发送消息之前,您需要一个主题订阅者,否则消息将被删除(根据主题语义)。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50854011

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档