ActiveMQArtemis在SpringBoot客户端定义的所有主题名称前添加“jms.topic.”
创始人
2024-07-24 13:31:41
0

可以使用以下代码来解决该问题:

首先,添加以下依赖项到pom.xml文件中:

org.springframework.boot spring-boot-starter-activemq-artemis

然后,在application.properties文件中配置以下参数:

spring.artemis.mode=native spring.artemis.host= spring.artemis.port=

接着,在Spring Boot应用程序中,使用以下代码来创建Artemis的连接工厂并设置相应的属性:

@Configuration public class ArtemisConfig {

@Value("${spring.artemis.host}")
private String artemisHost;

@Value("${spring.artemis.port}")
private String artemisPort;

@Bean
public ConnectionFactory connectionFactory() throws Exception {
    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
    connectionFactory.setBrokerURL("tcp://" + artemisHost + ":" + artemisPort);
    connectionFactory.setPrefixedDestinations(false); // Disable prefixed destinations
    connectionFactory.setUser("admin"); // Set username
    connectionFactory.setPassword("admin"); // Set password
    return connectionFactory;
}

}

注意:通过将setPrefixedDestinations设置为false,可以禁用主题名称前缀。

最后,在Spring Boot应用程序中使用以下代码来创建JmsTemplate并使用它来发布和订阅消息:

@Service public class MyService {

@Autowired
private JmsTemplate jmsTemplate;

public void sendMessage(String destinationName, String message) {
    jmsTemplate.send(destinationName, session -> session.createTextMessage(message));
}

public String receiveMessage(String destinationName) {
    return (String) jmsTemplate.receiveAndConvert(destinationName);
}

}

在以上代码中,destinationName参数表示主题名称。由于我们禁用了主题名称前缀,因此不需要添加“jms.topic.”前缀。

这样,我们就解决了ActiveMQ Artemis在Spring Boot客户端定义的所有

相关内容

热门资讯

Android Studio ... 要解决Android Studio 4无法检测到Java代码,无法打开SDK管理器和设置的问题,可以...
安装tensorflow mo... 要安装tensorflow models object-detection软件包和pandas的每个...
安装了Laravelbackp... 检查是否创建了以下自定义文件并进行正确的配置config/backpack/base.phpconf...
安装了centos后会占用多少... 安装了CentOS后会占用多少内存取决于多个因素,例如安装的软件包、系统配置和运行的服务等。通常情况...
按照Laravel方式通过Pr... 在Laravel中,我们可以通过定义关系和使用查询构建器来选择模型。首先,我们需要定义Profile...
按照分类ID显示Django子... 在Django中,可以使用filter函数根据分类ID来筛选子类别。以下是一个示例代码:首先,假设你...
Android Studio ... 要给出包含代码示例的解决方法,我们可以使用Markdown语法来展示代码。下面是一个示例解决方案,其...
Android Retrofi... 问题描述:在使用Android Retrofit进行GET调用时,获取的响应为空,即使服务器返回了正...
Alexa技能在返回响应后出现... 在开发Alexa技能时,如果在返回响应后出现问题,可以按照以下步骤进行排查和解决。检查代码中的错误处...
Airflow Dag文件夹 ... 要忽略Airflow中的笔记本检查点,可以在DAG文件夹中使用以下代码示例:from airflow...