0
votes

I am trying to create an ActiveMQ Artemis queue with last-value property enabled.

My app is using Spring Boot 2.2.6, and i am using Artemis as an embedded broker.


Spring Boot has a spring.artemis.embedded.queues property, which i tried to set as follows:

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

But that doesn't seem to work.

The Artemis documentation mentions 2 ways of configuring the queue:

  1. Using a broker.xml configuration file, but i couldn't make this work.
  2. Getting hold of a CORE session object, but I didn't manage to get hold of that object via Spring.

Is there an easy way to configure a last-value queue using Spring Boot, either via application.yml, or via Java/Kotlin configuration ?


Here is my test code:

@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)
  }
}
1

1 Answers

0
votes

Digging through Spring Boot's code, I found out one can provide a ArtemisConfigurationCustomizer to :

customize the Artemis JMS server Configuration before it is used by an auto-configured EmbeddedActiveMQ instance

@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)
      )
    }
  }
}