简体   繁体   English

JMS客户端如何注意新消息

[英]How JMS client notice about new message

I'm learning JMS and wonder how a JMS client (eg MessageListener) can notice about a new message in queue it registed. 我正在学习JMS,想知道JMS客户端(例如MessageListener)如何在注册的队列中注意到新消息。 Is it frequently send requests to broker via TCP to see if there's a new message? 是否经常通过TCP将请求发送给代理,以查看是否有新消息? If so, is this request synchronousor asynchronous? 如果是这样,此请求是同步还是异步?

1) First of all, JMS does not have something called absolute synchronous messaging. 1)首先, JMS没有所谓的绝对同步消息传递。 You can definitely implement so called JMS Synchronous messaging by implementing Sync service methods but in fact it just appears to be mimicking as Synchronous messaging . 您绝对可以通过实现Sync服务方法来实现所谓的JMS Synchronous messaging ,但实际上,它似乎只是在模仿“ Synchronous messaging In fact it is also Async Messaging . 实际上,它也是Async Messaging

2) Technically it is the JMS Server / Broker which sends Messages to Message Consumers through dedicated queues . 2)从技术上讲,是JMS Server / Broker通过专用队列消息发送给Message Consumers Broker simply delivers the message to Message Consumer's onMessage() method. Broker只是将消息传递Message Consumer's onMessage()方法。 And then Container executes onMessage() method. 然后, Container执行onMessage()方法。

JMS is just an API. JMS只是一个API。 It does not specify any wire level protocol. 它没有指定任何线级协议。 So you can't really tell how the client will behave with the broker. 因此,您无法真正分辨出客户在经纪人中的表现。 It could use a homing piegon for all we know. 对于我们所知道的一切,它可能会使用归位的方格。 Ok, maybe not, but brokers like WebSphere MQ and ActiveMQ both supply in memory transport as well as TCP based. 好的,也许不是,但是像WebSphere MQ和ActiveMQ这样的代理都提供内存传输以及基于TCP的服务。

Most vendors have thier own properitary protocols even though AMQP is visible on the horizon as a wire protocol standard (but far from all vendors have started to look at it). 即使AMQP作为一种有线协议标准在地平线上也可以看到,但大多数供应商都有自己的专有协议(但远没有所有供应商都开始考虑它了)。

When talking TCP there is no need to poll as long as there is a live connection going on. 在谈论TCP时,只要正在进行实时连接,就无需轮询。 The broker can easily notify the client that there is a new message published while the client sleeps and the other way around. 代理可以轻松地通知客户端在客户端睡眠时有新消息发布,反之亦然。

A common way, however, is to actually do poll. 但是,一种常见的方法是实际进行轮询。 But rather poll for consumer.receive(TIMEOUT); 而是轮询consumer.receive(TIMEOUT); in some longer intervals (seconds). 在更长的时间间隔(秒)内。 This makes it possible to use distributed transactions in frameworks like spring. 这样就可以在像spring这样的框架中使用分布式事务。 Still the broker sends actual TCP messages to the client on demand. 代理仍然按需向客户端发送实际的TCP消息。

If it would not have been like this, then JMS/Messaging would not have been such a fast, wide psread and scalable technology 如果不是这样,那么JMS / Messaging就不会是一种如此快速,广泛的psread和可扩展的技术。

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

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