Genel InMemory Java

Project Structure and Hello World With RabbitMQ

February 27, 2021

I want to show you my new modular project structure and how to send a message with RabbitMQ.
My new project’s name is EndlessHope, it has a modular structure because we need a regular project structure.
We will create a few micro-projects and API.
Firstly, we need a Core project. The Core project will have util, models, enums, and some classes.
And of course, we need one sender (produce) project. It will just send text messages, but later, we are going to change it with a modular structure and I’m going to upload Github you will check my codes.

I'm usually getting config from, because I want to change any config I change any config in and restart project I don’t need any hardcode change and deploy and I’m using slf4j for logs.

You can use default config but I will have big project and we I should adjustable with configs and detailed. I’m getting host and port.

for (int i = 0; i < hostsAr.length; i++) {
            hostPort = hostsAr[i];
            ar = hostPort.split(":");
            addresses[i] = new Address(ar[0], Integer.parseInt(ar[1]));

Creating new connection factory and create new connection from factory with my addresses. After we need new channel and we should declare to Queue.

ConnectionFactory factory = new ConnectionFactory();

connection = factory.newConnection(addresses);
channel.queueDeclare(rabbitmqQueuename, false, false, false, null);

Finally we sent message.

for (int i = 0; i < 100; i++) {
                String message = "ENSLESS HOPE!" + i;
                channel.basicPublish("", rabbitmqQueuename, null, message.getBytes());
      "count: " + i);

You can check all code here.

See you Receiving guys!



Sercan Toğrul
Java Developer - Kyrenia

I'm a java developer. I'm from Turkey but I live in Cyprus. You can see my skills and my notes here. Do you have a question you can send me email and I will answer!