I am using Java with ActiveMQ for sending messages from Embedded-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.
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. The reason for this is to limit the CPU and disk usage. For example: Produce message 1, attempt to send message. 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.
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.
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. 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. 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.