Spring JmsTemplate特定目标消息持久化

huangapple go评论68阅读模式
英文:

Spring JmsTemplate destination specific message persistence

问题

我正在使用JmsTemplate(spring-jms-5.2.8)将消息发送到嵌入式ActiveMQ代理到多个主题。我希望其中一些主题是持久的(发送到它们的消息将被持久化),而另一些主题则不是。不幸的是,JmsTemplate似乎在全局范围内配置递送模式=通过它发送的所有消息(需要启用QOS)。

直接在消息上设置传递模式是无效的,因为它稍后会被覆盖。

jmsTemplate.convertAndSend(destination, event, message -> {
    message.setJMSDeliveryMode(XXX);
    return message;
});

什么是最佳解决方案?难道通过JmsTemplate发送的所有消息都必须是持久的或非持久的吗?我必须创建两个单独的JmsTemplates吗?这是一个好方法吗?至于我传入的连接工厂呢?同一个连接工厂可否用于两个模板?

谢谢。

英文:

I am using a JmsTemplate (spring-jms-5.2.8) for sending messages to an embedded ActiveMQ broker to a several topics. I want some of the topics to be persistent (the messages sent to them to be persisted) and some of them not. Unfortunately, the JmsTemplate seems to be configuring the delivery mode globally = for all messages sent through it (requiring the QOS enabled).

Setting the delivery mode directly on the message doesn't help because it gets overridden later on.

jmsTemplate.convertAndSend(destination, event, message -> {
    message.setJMSDeliveryMode(XXX);
    return message;
});

What is the best solution to this? Do really all the messages going through the JmsTemplate have to be either persistent or non-persistent? Do I have to create two separate JmsTemplates? Is that a good approach? What about the connection factory I am passing in? Can the same connection factory be used for both templates?

Thanks.

答案1

得分: 1

我是否需要创建两个单独的JmsTemplates?这是一个好的方法吗?
是的;最简单的解决方案是定义2个模板。

那么上面提到的连接工厂呢?
不清楚您所指的“上面”。

您可以在每个模板中使用相同的工厂;它们将共享连接。

英文:

>Do I have to create two separate JmsTemplates? Is that a good approach?

Yes; the simplest solution is to define 2 templates.

>What about the connection factory above?

?? It's not clear what you mean by "above".

You can use the same factory in each template; they will share the connection.

huangapple
  • 本文由 发表于 2020年9月21日 23:28:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/63995392.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定