0

I have to design a system where Subscriber is slower than Producers. I cannot use any MQ solution(due to budget constraints). Can I use in-memory queue where the producer will put data into queue and Subscriber will poll in a specific interval? How to implement using Java 7.

Can I use Google Guava EventBus for the same?

If yes either of the cases then how to implement the solution or any other low cost alternative solution.

Debopam
  • 3,198
  • 6
  • 41
  • 72

1 Answers1

0

An EventBus is good for decoupling parts of the system, so that the producers only knows the EventBus and the consumers knows it indirectly by means of @Subscribe (some code must know both the consumer and the EventBus, so it can call register).

You may or may not need such decoupling. The EventBus may deliver events synchronously on the same thread (the default) or using a provided Executor. If you don't want the producers to be slowed down by the subscribers, then you can use the asynchronous version.

If you want that the producers don't get slowed down, then you may use some BlockingQueue from java.util.concurrent. Look at LinkedBlockingQueue and ArrayBlockingQueue, if you want to apply backpressure (i.e., to slow down the produces if the queue grows big).

If you don't care that both producers and consumers must see your queue, then you don't need an EventBus. If you do, then you can use it e.g., so that the producers post an event subscribed by a thread filling the queue. Or there may be a thread polling the queue and posting to the bus.

Or both, but don't over-engineer it, just KISS.

AFAICT, proper message queue is an overkill when working inside of a single Java process.

You should add more details to get a recommendation.

maaartinus
  • 44,714
  • 32
  • 161
  • 320
  • Thanks for your suggestion. My requirement is producer and subscriber shouldn't know each other. There can be multiple subscribers for a given input type. A producer will push messages and Subscriber will read it one by one at its own pace. Please let me know if you have any other suggestion. I am using Spring 4, Java 7 etc. – Debopam Dec 01 '17 at 05:31