JMS 是满足持久阻塞队列需求的答案吗?
我正在创建一个由 Log4J 附加程序组成的库,该附加程序将事件异步发送到远程服务器。当发出日志语句时,附加程序将异步地将事件记录到本地队列中,然后消费者池将检索该事件并将其发送到远程。
完全内存中的解决方案是创建一个 BlockingQueue 来处理并发问题。但是,我希望队列能够被持久化,这样如果远程服务器不可用,我就不会无限制地增长队列,或者在有界队列的情况下开始丢弃消息。
我正在考虑使用嵌入式 H2 数据库在本地存储事件,然后使用轮询机制来检索事件并将其发送到远程。我宁愿使用 BlockingQueue 而不是轮询数据库表。
JMS 是答案吗?
编辑:
如果 JMS 是答案,而且似乎正在朝着这个方向发展,那么是否有人对轻量级、可嵌入 JMS 解决方案有建议,该解决方案可以配置为仅接受进程中的消息?换句话说,我不想,也可能不会被允许,打开一个 TCP 套接字来侦听。
编辑:
我现在已经嵌入了 ActiveMQ,它似乎正在工作。谢谢大家。
I'm creating a library that consists of a Log4J appender that asynchronously sends events to a remote server. When a log statement is made, the appender will asynchronously record the event into a local queue which a pool of consumers will then retrieve and send to the remote.
The completely in-memory solution would be to create a BlockingQueue which would handle the concurrency issue. However, I'd like for the queue to be persisted so that if the remote server is not available I don't grow the queue unbounded or start to discard messages in the case of a bounded queue.
I was thinking of using an embedded H2 database to store the events locally and then use a polling mechanism to retrieve events and send to the remote. I would much rather use a BlockingQueue than to poll a database table.
Is JMS the answer?
EDIT:
If JMS is the answer, and it seems to be going that way, does anyone have recommendations on a lightweight, embeddable JMS solution that can be configured to only accept messages in-process? In other words, I do not want to, and possibly will not be allowed to, open up a TCP socket on which to listen.
EDIT:
I've got ActiveMQ embedded now and it seems to be working. Thanks all.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Bob Lee 不久前开源了一个非常简单的磁盘支持队列,https://github.com/square/retrofit/blob/master/modules/android/src/retrofit/io/QueueFile.java - 可能会有所帮助,而且肯定要容易得多如果你能接受本地持久性,就引入比JMS 更好的方法。
该类是独立的——可以复制和粘贴。
Bob Lee open sourced a very simple disk backed queue a while back, https://github.com/square/retrofit/blob/master/modules/android/src/retrofit/io/QueueFile.java -- may be helpful, and is certainly a lot easier to introduce than JMS if you can accept local durability.
This class is standalone -- it can be copied and pasted.
您可以使用 JMS 将消息异步发送到远程计算机(假设它当然可以接收它们),Log4j 有一个 JMS Appender 您可以用于此目的。
You could use JMS to asynchronously send messages to a remote machine (assuming it can receive them of course), Log4j has a JMS Appender you can use for this.
您绝对可以使用 JMS 来实现此目的。据我了解,您正在使用 Log4J JMS 附加程序。该组件将消息发送到预先配置的 JMS 目标(通常是队列)。您可以将此队列配置为持久化。在这种情况下,插入队列的所有消息将自动存储在某个持久存储中(通常是数据库)。不幸的是,此配置是特定于供应商的(取决于 JMS 供应商),但通常非常简单。请参阅您的 JMS 提供商的文档。
You can definitely use JMS for this purpose. As far as I understand you are using the Log4J JMS appender. This component sends messages to pre-configured JMS destination (typically queue). You can configure this queue to be persisted. In this case all messages inserted into the queue will be automatically stored in some persisted store (typically database.). Unfortunately this configuration is vendor specific (depends on the JMS vendor), but usually is very simple. Please refer to the documentation of you JMS provider.
看看这是否有效
此代码应该适合您 - 它是内存中的持久阻塞队列 - 需要一些文件调整但应该可以工作
See if this works
This code should work for you - its an in memory persistent blocking queue - needs some file tuning but should work