Skip to content

Commit

Permalink
adding rabbitmq services.
Browse files Browse the repository at this point in the history
  • Loading branch information
bscpaz committed Jul 11, 2023
1 parent fe100a6 commit efde8ed
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package br.com.bscpaz.publisher.configurations;

public class RabbitmqConfig {

public static final String JUSTICE_V1_DOCS_EXCHANGE = "justice.v1.documents";
public static final String JUSTICE_V1_DOCS_ROUTING_KEY = "document-signed.";

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ public class ResponseDTO<T> {

private String message;

private T result;
private T payload;

public ResponseDTO() {
}

public ResponseDTO(boolean isSuccess, T t) {
this.isSuccess = isSuccess;
this.result = t;
this.payload = t;
}

public ResponseDTO(boolean isSuccess, String message, T t) {
this.isSuccess = isSuccess;
this.message = message;
this.result = t;
this.payload = t;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,23 @@

public class ResponseUtil {

public static <T> ResponseEntity<ResponseDTO<T>> success(T conteudo) {
ResponseDTO<T> dto = new ResponseDTO<T>(true, conteudo);
public static <T> ResponseEntity<ResponseDTO<T>> success(T payload) {
ResponseDTO<T> dto = new ResponseDTO<T>(true, payload);
return new ResponseEntity<>(dto, HttpStatus.OK);
}

public static <T> ResponseEntity<ResponseDTO<T>> badRequest(T conteudo, String mensage) {
ResponseDTO<T> dto = new ResponseDTO<T>(false, mensage, conteudo);
public static <T> ResponseEntity<ResponseDTO<T>> success(String message, T payload) {
ResponseDTO<T> dto = new ResponseDTO<T>(true, message, payload);
return new ResponseEntity<>(dto, HttpStatus.OK);
}

public static <T> ResponseEntity<ResponseDTO<T>> badRequest(T payload, String message) {
ResponseDTO<T> dto = new ResponseDTO<T>(false, message, payload);
return new ResponseEntity<>(dto, HttpStatus.BAD_REQUEST);
}

public static <T> ResponseEntity<ResponseDTO<T>> internalServerError(T payload, String message) {
ResponseDTO<T> dto = new ResponseDTO<T>(false, message, payload);
return new ResponseEntity<>(dto, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
package br.com.bscpaz.publisher.controllers.v1.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;

import br.com.bscpaz.publisher.controllers.dtos.ResponseDTO;
import br.com.bscpaz.publisher.controllers.utils.ResponseUtil;
import br.com.bscpaz.publisher.controllers.v1.BasicPublisherController;
import br.com.bscpaz.publisher.services.BasicPublisherService;

@RestController
public class BasicPublisherControllerImpl implements BasicPublisherController {

@Autowired
private BasicPublisherService basicPublisherController;

@Override
public ResponseEntity<ResponseDTO<String>> helloWorldRabbitmq() {
return ResponseUtil.success("Message published into rabbitmq!");
try {
String message = basicPublisherController.helloWorldRabbitmq();
return ResponseUtil.success(message, null);
} catch (Exception e) {
return ResponseUtil.internalServerError(e.getMessage(), "Sorry, something went wrong.");
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package br.com.bscpaz.publisher.services;

public interface BasicPublisherService {

String helloWorldRabbitmq();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package br.com.bscpaz.publisher.services.impl;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import br.com.bscpaz.publisher.configurations.RabbitmqConfig;
import br.com.bscpaz.publisher.services.BasicPublisherService;

@Service
public class BasicPublisherServiceImpl implements BasicPublisherService {

@Autowired
private RabbitTemplate rabbitTemplate;

@Override
public String helloWorldRabbitmq() {
String helloWorld = "Hello World";
Message message = new Message(helloWorld.getBytes());

rabbitTemplate.send(
RabbitmqConfig.JUSTICE_V1_DOCS_EXCHANGE,
RabbitmqConfig.JUSTICE_V1_DOCS_ROUTING_KEY + "1",
message);

return "Message has been sent to RabbitMQ!";
}
}
1 change: 0 additions & 1 deletion publishers/src/main/resources/application.properties

This file was deleted.

7 changes: 7 additions & 0 deletions publishers/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
spring:
rabbitmq:
host: localhost
port: 5672
username: system_user
password: 123456
virtual-host: justice-prd

0 comments on commit efde8ed

Please sign in to comment.