简体   繁体   English

为JMS客户端指定消息持久性

[英]Specifying Message Persistence for JMS client

I'm reading this section of Java EE tutorial. 我正在阅读Java EE教程的这一部分。 http://download.oracle.com/javaee/6/tutorial/doc/bncfu.html#bncfy http://download.oracle.com/javaee/6/tutorial/doc/bncfu.html#bncfy

And have a question: If I have a JMS client (not Server) that produces messages and sends them to a destination queue that is on the server, does this producer.setDeliveryMode(DeliveryMode.PERSISTENT); 并且有一个问题:如果我有一个生成消息的JMS客户端(而不是服务器)并将它们发送到服务器上的目标队列,那么这个producer.setDeliveryMode(DeliveryMode.PERSISTENT); still applies? 仍然适用?

I mean does JMS client support any mechanism to persist messages or that is only comes with the provider/sever software? 我的意思是JMS客户端是否支持任何持久化消息的机制,或者只提供提供者/服务器软件?

Thanks 谢谢

Since JMS is just a specification, there is nothing that would prevent an implementation from providing some level of message persistence at the client. 由于JMS只是一个规范,因此没有什么能阻止实现在客户端提供某种级别的消息持久性。 However, in practice all implementations (that I am aware of anyway) delegate that to the broker. 但是,在实践中,所有实现(无论如何我都知道)将其委托给代理。

Keep in mind that messaging was originally designed to have a broker at every node in the same way that every node also had a TCP/IP, LU6.2 or other transport stack. 请记住,消息传递最初设计为在每个节点上都有一个代理,就像每个节点也有一个TCP / IP,LU6.2或其他传输堆栈一样。 In that sense messaging was strictly supposed to be a transport, not a central service like a database. 从这个意义上讲,消息传递严格地说是一种传输,而不是像数据库这样的中央服务。 The intention was to provide a local service that insulated the application from unavailability of the network and also from the myriad of synchronous transport protocols that were available. 其目的是提供一种本地服务,使应用程序与网络不可用以及可用的无数同步传输协议隔离开来。 In this model, the broker was always local and the only network communication was between two brokers. 在此模型中,代理始终是本地的,唯一的网络通信是在两个代理之间。

Over the years, messaging added a client capability but this is more about licensing costs than architecture. 多年来,消息传递增加了客户端功能,但这更多地是关于许可成本而不是架构。 The messaging client connection re-introduced a dependency on synchronous network connectivity that the transport had originally been intended to shield the application from. 消息传递客户端连接重新引入了对传输最初旨在保护应用程序的同步网络连接的依赖性。 We have now come full circle as your question illustrates - a requirement for a local queuing to shield the application from unavailability of the network. 正如您的问题所示,我们现在已经完全循环 - 需要本地排队来保护应用程序免受网络不可用的影响。 Except now the application requiring a local persistence for messages is in fact the (supposedly) asynchronous messaging application. 除了现在需要消息的本地持久性的应用程序实际上是(假设的)异步消息传递应用程序。

We could of course build a local mini-broker to queue messages before they get to the central broker. 我们当然可以构建一个本地迷你代理来在消息到达中央代理之前对消息进行排队。 But before we go making the client code much more complex (and inviting an infinite recursion of backing our async messaging with yet more async messaging) I would recommend taking a second look at the original messaging architecture - put the broker local to the applications which require that level of persistence. 但在我们开始使客户端代码变得更加复杂之前(并且邀请无限递归来支持我们的异步消息传递以及更多异步消息传递)我建议再看看原始消息传递体系结构 - 将代理本地放在需要的应用程序中那种持久性。

One approach to this is to treat service provider apps differently than service consumer apps. 一种方法是将服务提供商应用程序与服务消费者应用程序区别对待。 It is the service providers who require deep, persistent message stores and, because they are often transactional, cannot be allowed to fail over to a different instance of the broker (in this case "different" as recognized by the XA resource manager). 服务提供者需要深度,持久的消息存储,并且因为它们通常是事务性的,所以不能允许故障转移到代理的不同实例(在这种情况下,由XA资源管理器识别的“不同”)。

On the other hand, simple request/reply apps can continue to anonymously connect over the network to a lightweight tier of brokers with no permanent queues on them. 另一方面,简单的请求/回复应用程序可以继续通过网络匿名连接到轻量级的代理,而不需要永久队列。 These apps issue a request message outside of syncpoint and wait for the reply on a dynamic queue. 这些应用程序在同步点之外发出请求消息,并等待动态队列上的回复。 If they fail over, they can just reissue the request and the reply will come to the new node. 如果他们进行故障转移,他们可以重新发出请求,并且回复将转到新节点。 These are ideal candidates for networked, client-based messaging since they have no affinity to a particular broker. 这些是联网的基于客户端的消息传递的理想候选者,因为它们与特定代理没有亲和力。 As long as there is a network hop between client and server apps, there is no need to make sure that clients fail over with servers, etc. Service providers have local brokers and service consumers have two (or more) lightweight central brokers to connect to. 只要客户端和服务器应用程序之间存在网络跳跃,就不需要确保客户端使用服务器等进行故障转移。服务提供商拥有本地代理,服务使用者可以连接两个(或更多)轻量级中央代理。

Of course, this does not meet every async messaging requirement but it does provide a solution that provides highest reliability for systems of record and still conserves license costs by allowing service requestors to share centralized brokers. 当然,这不符合每个异步消息传递要求,但它确实提供了一种解决方案,为记录系统提供了最高的可靠性,并且通过允许服务请求者共享集中式代理,仍然可以节省许可证成本。

wow, a lot of info by T.Rob, though not sure if he clearly answered the question. 哇,T.Rob的很多信息,虽然不确定他是否清楚地回答了这个问题。 :) :)

The short answer is yes, it does apply. 简短的回答是肯定的,它确实适用。 In fact, it's meant to be specified by the message producing client to tell the broker how to handle it. 实际上,它意味着由生成客户端的消息指定,以告诉代理如何处理它。

There's not much point in keeping it persistent locally since you'll get JMSException when trying producer.send(..) if the broker (server) is down. 保持本地持久性没有多大意义,因为如果代理(服务器)关闭,在尝试使用producer.send(..)时会遇到JMSException。

-Ed Y. -Ed Y.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM