I have this ServiceA that uses JMS that sends to a queue for ServiceB (which uses azure functions + service bus). These are my steps:
ServiceA: I set up my correlationId and replyTo via JmsTemplate then call jmsTemplate.convertAndSend()
ServiceB: is an azure function that listens to a queue. It processes the message received, then I build a ServiceBusClient().sender() to send back to ServiceA
ServiceA: is still listening for a reply via jmsTemplate.receiveSelected(), filtering by the correlation id I set. However, my message selector doesn't seem to work and receives just any message without filtering.
My implementation are as follows:
This is Service A:
class ServiceA(
private val jmsTemplate: JmsTemplate
) {
fun execute() {
val uuid = UUID.randomUUID().toString()
jmsTemplate.convertAndSend("queue_service_B", messageString) {
it.jmsCorrelationID = uuid
it.jmsReplyTo = it.jmsDestination
it
}
val response = jmsTemplate.receiveSelected("queue_service_A", "JMSCorrelationID='$uuid'")
// process response
// the correlationId of the response is usually whichever message got sent to queue_service_A first
}
}
This is Service B:
@FunctionName("serviceB")
fun serviceBFunc(
@ServiceBusQueueTrigger(
name = "serviceBQueue",
queueName = "queue_service_B",
connection = "connection_string",
) message: String,
@BindingName("CorrelationId") correlationId: String,
ctx: ExecutionContext
) {
// process message
// then build sender client
val sender = ServiceBusClientBuilder()
.connectionString(connectionString)
.sender()
.queueName("queue_service_A")
.buildClient()
val serviceBusMessage = ServiceBusMessage("Test message")
.apply {
setCorrelationId(correlationId)
setContentType("application/json")
}
sender.use {
it.sendMessage(serviceBusMessage)
}
}
As indicated here in the documentation, the message selector key for correlation id should be JMSCorrelationID. I have also tried variations of the word. Service B sets up the correlation Id just fine as well with no issues.
What confuses me as well is that it still receives messages even when the selector does not fit the correlation id in the queue. I wonder what could be done to fix this? Any help would be appreciated.