持久订阅能否在客户端重启后继续存在?

发布于 2024-09-10 08:38:24 字数 456 浏览 3 评论 0原文

如果我使用持久订阅,我可以重新启动客户端并重新订阅而不会丢失任何消息吗? (假设我的客户没有以任何方式取消订阅。可以说它只是崩溃了)。

让我澄清一下。 JMS 1.1 规范如下:

9.3.3.2 使用持久订阅重新连接到主题

/* Reconnect to a durable subscription */
session.createDurableSubscriber(newsFeedTopic, "mySubscription");

但是,需要注意一些重要的限制:

  • 客户端必须附加到同一个连接。
  • 目标名称和订阅名称必须相同。
  • 如果指定了消息选择器,则它也必须相同。

我对“相同的连接”部分感兴趣。目前尚不清楚“相同”在这种情况下意味着什么。

If I use durable subscription, can I restart my client and resubscribe without loosing any messages? (Assuming, my client does not unsubscribe in any way. Lets say it just crashes).

Let me clarify. JMS 1.1 Spec says the following:

9.3.3.2 Reconnecting to a Topic using a Durable Subscription

/* Reconnect to a durable subscription */
session.createDurableSubscriber(newsFeedTopic, "mySubscription");

However, there are some important restrictions to be aware of:

  • The client must be attached to the same Connection.
  • The Destination and subscription name must be the same.
  • If a message selector was specified, it must also be the same.

That "same Connection" part interests me. It is not clear what "same" means in this context.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

岁月苍老的讽刺 2024-09-17 08:38:24

在规范中,请查看 4.3,其中提到 Connection 对象可以包含唯一的客户端标识符,而 4.3.2 则说明...

客户端标识符的目的是将连接及其对象关联起来
由提供商代表客户维护的状态。根据定义,
由客户端标识符标识的客户端状态只能由一个客户端“使用”
一次。 JMS 提供者必须防止同时执行的客户端使用
它。

因此,这里的目的是持久订阅包含一个唯一的标识符,以便当应用程序重新订阅时,它可以附加到正确的状态存储,在没有该标识符的情况下,消息已在其中排队。由于执行此操作的首选方法是在特定于客户端的连接对象中对标识符进行编码,因此规范指示您使用相同的连接重新连接,但在本例中,这意味着相同管理对象 不是同一个连接句柄(使用 WMQ 术语)。

当然,您不需要管理对象,应用程序可以动态生成连接。在这种情况下,您需要安排它对连续订阅使用相同的客户端标识符。

In the spec, take a look at 4.3 where it mentions that the Connection object can contain a unique client identifier and 4.3.2 which states...

The purpose of the client identifier is to associate a connection and its objects
with a state maintained on behalf of the client by a provider. By definition, the
client state identified by a client identifier can be ‘in use’ by only one client at
a time. A JMS provider must prevent concurrently executing clients from using
it.

So the intent here is that the durable subscription contains a unique identifier so that when the app resubscribes it can be attached to the correct state-store where messages have been queued up in its absence. Since the preferred way of doing this is to code the identifier in a client-specific connection object, the spec directs you to reconnect using the same connection but in this case that means the same administered object not the same connection handle (to use the WMQ terminology).

Of course, you don't need an administered object, the app can generate a connection dynamically. In that case you'd need to arrange for it to use the same client identifier for successive suscriptions.

潦草背影 2024-09-17 08:38:24

如果持久订阅没有活动订阅者,JMS 会保留订阅的消息,直到订阅者收到消息,或者直到消息过期,或者直到删除持久订阅。这使得订阅者应用程序能够在一段时间内与 JMS 提供者断开连接,然后重新连接到提供者并处理在其缺席期间发布的消息。

If there is no active subscriber for a durable subscription, JMS retains the subscription's messages until they are received by the subscriber, or until they expire, or until the durable subscription is deleted. This enables subscriber applications to operate disconnected from the JMS provider for periods of time, and then reconnect to the provider and process messages that were published during their absence.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文