简体   繁体   English

ActiveMQ仅在必要时才保留在磁盘上

[英]ActiveMQ persist on disk only when necessary

I am using Java with ActiveMQ for sending messages from Embedded-Linux. 我将Java与ActiveMQ结合使用,用于从嵌入式Linux发送消息。 My requirements are that messages should be persisted if the destination broker is not available. 我的要求是,如果目标代理不可用,则消息应保留。 I chose KahaDB as the persistence adapter in order for the messages to survive a broker restart. 我选择KahaDB作为持久性适配器,以便消息在代理重新启动后继续存在。

broker = new SslBrokerService();

KahaDBPersistenceAdapter kahaDBPersistenceAdapter=new KahaDBPersistenceAdapter();
kahaDBPersistenceAdapter.setJournalMaxFileLength(16 * 1024 * 1024);
broker.setPersistenceAdapter(kahaDBPersistenceAdapter);

/** Connector setup code */
broker.start();

Even though I have limited the maximum file size to 16MB i would like to ONLY persist messages if the destination broker/consumer is not available. 即使我将最大文件大小限制为16MB,但如果目标代理/消费者不可用,我也希望保留消息。 The reason for this is to limit the CPU and disk usage. 这样做的原因是限制CPU和磁盘使用率。 For example: Produce message 1, attempt to send message. 例如:产生消息1,尝试发送消息。 If successful persistence should not occur since I am not interested in re-sending already sent data ( or should occur only in memory ) . 如果不应成功进行持久化,因为我对重新发送已发送的数据不感兴趣(或者应该仅在内存中进行)。 Produce messages 2,3,4 but destination broker is unavailable, then persist messages on disk such that in the unlikely shutdown of borker messages will survive. 生成消息2、3、4,但目标代理不可用,然后将消息持久保存在磁盘上,以便在不太可能的情况下关闭borker消息后,这些消息将继续存在。

After going back and forth through the documentation of ActiveMQ I have not found any answer for my use case so I am asking this great community if what I am looking for is actually possible. 在来回浏览ActiveMQ的文档后,我没有找到关于我的用例的任何答案,因此我问这个伟大的社区,我所寻找的东西是否真的可能。

You would have to write a custom plugin to get that exact scenario. 您必须编写一个自定义插件才能获得确切的场景。 JMS does not describe a use case to persist if only the consumer is not available, b/c the reliability contract is also with the producer. 如果只有消费者不可用,JMS不会描述用例的持久性,b / c可靠性合同也与生产者签订。 I think a store-and-forward design would be what you are looking for. 我认为存储和转发设计将是您想要的。 Configure embeddedBroker to use a static: networkConnector to send it to the destination broker. 配置EmbeddedBroker以使用static:networkConnector将其发送到目标代理。 ActiveMQ will automatically push messages up to the destination server when available, and queue them up on the embedded server if the remote broker is unavailable. ActiveMQ将自动将消息推送到目标服务器(如果可用),如果远程代理不可用,则将消息在嵌入式服务器上排队。

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

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