The following diagram provides an overview of the scenario that we will implement:
For publish-subscribers we can use a fanout exchange and bind any number of queues to that exchange regardless of the binding key. The PublishSubscribeReceiver
class can be used to bind a specified queue to a fanout exchange and receive messages from it:
import java.io.IOException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.rabbitmq.client.Channel; import com.rabbitmq.client.Connection; import com.rabbitmq.client.ConnectionFactory; import com.rabbitmq.client.ConsumerCancelledException; import com.rabbitmq.client.QueueingConsumer; import com.rabbitmq.client.ShutdownSignalException; public class PublishSubscribeReceiver { private final static String EXCHANGE_NAME = "pubsub_exchange"; private final static Logger LOGGER = LoggerFactory.getLogger(Sender.class); private Channel channel = null; private Connection connection = null; public...