简体   繁体   English

没有持久性的 ActiveMQ

[英]ActiveMQ without persistence

I'd like to set up a publisher-subscriber based communication protocol between a server producing messages and many clients receiving them.我想在生成消息的服务器和接收它们的许多客户端之间建立一个基于发布者-订阅者的通信协议。 After a bit of research, I decided to go with ActiveMQ.经过一番研究,我决定使用 ActiveMQ。 I looked at a few tutorials and the ActiveMQ site and set up the broker as follows:我查看了一些教程和 ActiveMQ 站点,并按如下方式设置了代理:

BrokerService broker = new BrokerService();
broker.setPersistent(false);
broker.addConnector("tcp://localhost:61616");
broker.start();

I only need the message passing functionality, no database persistence or anything alike.我只需要消息传递功能,不需要数据库持久性或类似的东西。 However, when I start the application, a activemq-data folder is created regardless of the the configuration.但是,当我启动应用程序时,无论配置如何,都会创建一个 activemq-data 文件夹。 This in turn causes an exception the next time I start the broker.这反过来会在我下次启动代理时导致异常。

SEVERE: Failed to start ActiveMQ JMS Message Broker. Reason: java.io.EOFException: Chunk stream does not exist at page: 0

Is this a bug or am I not setting up the broker correctly (using ActiveMQ 5.4.1)?这是错误还是我没有正确设置代理(使用 ActiveMQ 5.4.1)? How can I disable persistence, so the additional data storage is not created?如何禁用持久性,以便不创建额外的数据存储? Also, I prefer to configure the broker from within the Java application and not through an xml file.此外,我更喜欢在 Java 应用程序中配置代理,而不是通过 xml 文件。

Cheers, Max干杯,马克斯

You can also set the delivery mode for your message producer.您还可以为消息生产者设置传递模式。

messageProducer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);

Integer values allowed by JMS are: JMS 允许的整数值为:

    int NON_PERSISTENT = 1;
    int PERSISTENT = 2;

In my case remove all of the kahadb data files from the following directory helps:在我的情况下,从以下帮助目录中删除所有 kahadb 数据文件:

$ ls /var/lib/activemq/main/data$ cd kahadb
db-1.log  db.data  db.redo  lock

then:然后:

sudo service activemq restart

and everything back to work一切都恢复了

This is not normal behaviour but a bug in KahaDB (the default persistence store in Activemq)这不是正常行为,而是 KahaDB(Activemq 中的默认持久性存储)中的一个错误

You can see info on Bug 2935 of ActiveMQ .您可以查看有关ActiveMQ 的错误 2935 的信息。

You could solve this by choosing a different persistence engine, although i strangly had this problem a couple of times and then it dissapeared您可以通过选择不同的持久性引擎来解决这个问题,尽管我奇怪地遇到了几次这个问题然后它消失了

if using maven pom, then switch to `如果使用 maven pom,则切换到 `

<dependency>
    <groupId>org.apache.activemq</groupId>
    <artifactId>activemq-all</artifactId>
    <version>5.8.0</version>
</dependency>

` also don't forget to clear out the contents in KahaDB and Scheduler. ` 也不要忘记清除KahaDB 和Scheduler 中的内容。 it also helps to turn the scheduler off, if not needed.如果不需要,它还有助于关闭调度程序。

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

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