【问题标题】:How to create Artemis last-value queue with Spring Boot 2.2 and embedded broker?如何使用 Spring Boot 2.2 和嵌入式代理创建 Artemis 最后值队列?
【发布时间】:2020-08-05 11:40:32
【问题描述】:

我正在尝试创建一个启用了last-value 属性的 ActiveMQ Artemis 队列。

我的应用使用 Spring Boot 2.2.6,并且我使用 Artemis 作为嵌入式代理。


Spring Boot 有一个spring.artemis.embedded.queues 属性,我尝试设置如下:

spring.artemis.embedded.queues: myqueue?last-value-key=code

但这似乎不起作用。

Artemis 文档提到了 2 种配置队列的方法:

  1. 使用broker.xml 配置文件,但我无法完成这项工作。
  2. 获取了一个 CORE 会话对象,但我没有设法通过 Spring 获取该对象。

有没有一种简单的方法可以通过 application.yml 或通过 Java/Kotlin 配置使用 Spring Boot 配置最后值队列?


这是我的测试代码:

@ExtendWith(SpringExtension::class)
@SpringBootTest
class ArtemisTest(
  @Autowired private val jmsTemplate: JmsTemplate
) {

  @Test
  fun testMessage() {
    for(i in 1..5) {
      jmsTemplate.convertAndSend(
        "myqueue",
        "message $i"
      ) {
        it.also { it.setStringProperty("code", "1") }
      }
    }

    val size = jmsTemplate.browse("myqueue") { _: Session, browser: QueueBrowser ->
      browser.enumeration.toList().size
    }

    assertThat(size).isEqualTo(1)
  }
}

【问题讨论】:

    标签: spring-boot kotlin activemq-artemis


    【解决方案1】:

    挖掘 Spring Boot 的代码,我发现可以提供一个ArtemisConfigurationCustomizer 给:

    在使用 Artemis JMS 服务器配置之前对其进行自定义 自动配置 EmbeddedActiveMQ 实例

    @Configuration
    class ArtemisConfig : ArtemisConfigurationCustomizer {
      override fun customize(configuration: org.apache.activemq.artemis.core.config.Configuration?) {
        configuration?.let {
          it.addQueueConfiguration(
            CoreQueueConfiguration()
              .setAddress("myqueue")
              .setName("myqueue")
              .setLastValueKey("code")
              .setRoutingType(RoutingType.ANYCAST)
          )
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2017-02-08
      • 1970-01-01
      • 2017-11-30
      • 2021-10-30
      • 1970-01-01
      • 2016-12-09
      • 1970-01-01
      • 2014-04-12
      • 2015-12-02
      相关资源
      最近更新 更多