简体   繁体   English

如何将JMS队列视为临时存储?

[英]How do I treat JMS queue as a temporary storage?

I want to be able to pull and insert messages to and from a queue. 我希望能够将消息拉入队列或从队列中插入消息。 Is it possible to leverage JMS features for this, or should I need create a custom data structure for this? 是否可以为此使用JMS功能,或者是否需要为此创建自定义数据结构?

Please let me know if there is any other specific design pattern for a temporary storage. 请让我知道临时存储是否还有其他特定的设计模式。

Update : Since many asking for more detail, so here it is. 更新 :由于许多人要求更多细节,所以就在这里。 My requirement is to store a message in a queue from which multiple clients can push the data to, and also pull the data back from it as and when required. 我的要求是将消息存储在队列中,多个客户端可以将消息从队列中推送到该队列,也可以在需要时从队列中拉回数据。 This queue should be available to multiple clients. 该队列应可供多个客户端使用。 One message should be processed only once and if client is not able to process the data then message should return back to the queue. 一条消息应仅处理一次,如果客户端无法处理数据,则该消息应返回到队列。

It seems that you are asking multiple things in one question, so it might benefit you to clarify a little the individual points you need answered. 似乎您在一个问题中提出了多个问题,因此澄清您需要回答的个别问题可能会有所帮助。

Yes, it is possible to have JMS used as a 'temporary' storage, but it depends on what you mean by that and what you need. 是的,可以将JMS用作“临时”存储,但这取决于您的意思和需要。 Most JMS providers (such as ActiveMQ) allow you to do the following things on queues: 大多数JMS提供程序(例如ActiveMQ)都允许您在队列上执行以下操作:

  • Set a queue to durable (ie store on disk and if the queue gets restarted all messages are there) or non-durable (ie do not store on disk and if the queue gets restarted there will be no messages). 将队列设置为持久性(即,存储在磁盘上并且如果重新启动该队列,则所有消息都存在)或非持久性(即不存储在磁盘上,并且如果该队列重新启动,则将不存在消息)。
  • You can set an expiry time on messages, so that if they are not picked up on time they are discarded. 您可以为邮件设置到期时间,这样,如果未按时提取邮件,则将其丢弃。

This depends on what you are referring to as 'temporary storage'. 这取决于您所说的“临时存储”。 A JMS queue is not a database, its a messaging system. JMS队列不是数据库,而是一个消息传递系统。

Regarding data structures, you can serialize both normal Java Objects in an ObjectMessage and also text messages with the TextMessage . 关于数据结构,您既可以序列化ObjectMessage中的普通Java对象,也可以使用TextMessage序列化文本消息。 So you can pass through XML, JSON, CSV or whatever you want. 因此,您可以通过XML,JSON,CSV或任何您想要的内容。 You can also include special headers which you can use for routing or other meta-information associated with the message. 您还可以包括特殊的标头,这些标头可用于路由或与消息关联的其他元信息。 Again depends on what you mean by 'custom data structure'. 再次取决于您所说的“自定义数据结构”的含义。 You can also send a raw BytesMessage , or a MapMessage (key-value pairs), or a StreamMessage with different data types inside it one after the other. 您还可以发送原始的BytesMessageMapMessage (键-值对)或内部带有不同数据类型的StreamMessage ,一个接一个地发送。

If you need temporary storage in the literal sense, maybe you should look at embedded databases such as Derby or HSQLDB. 如果您需要字面意义上的临时存储,也许您应该查看诸如Derby或HSQLDB之类的嵌入式数据库。 I think they also have configurations to state whether data should stay in memory or go to disk after it gets too large. 我认为他们也有配置来声明数据过大之后应该保留在内存中还是保留到磁盘中。

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

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