Compare commits

1 Commits

7 changed files with 93 additions and 1 deletions

11
pom.xml
View File

@@ -43,6 +43,17 @@
<version>1.0.0</version> <version>1.0.0</version>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp-test</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId> <artifactId>spring-boot-starter-data-jpa</artifactId>

View File

@@ -0,0 +1,23 @@
package br.com.stackpanel.duck_api.config;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import static br.com.stackpanel.duck_api.entity.enums.QueueNames.QUEUE_NOTIFICATION_CAD;
import static br.com.stackpanel.duck_api.entity.enums.QueueNames.QUEUE_NOTIFICATION_ERROR;
@Configuration
public class RabbitConfig {
@Bean
public Queue queueNotificationError() {
return new Queue(QUEUE_NOTIFICATION_ERROR.label, true);
}
@Bean
public Queue queueNotificationCad() {
return new Queue(QUEUE_NOTIFICATION_CAD.label, true);
}
}

View File

@@ -0,0 +1,15 @@
package br.com.stackpanel.duck_api.entity.enums;
public enum QueueNames {
QUEUE_NOTIFICATION_ERROR("QUEUE_NOTIFICATION_ERROR"),
QUEUE_NOTIFICATION_CAD("QUEUE_NOTIFICATION_CAD");
public final String label;
private QueueNames(String label) {
this.label = label;
}
}

View File

@@ -0,0 +1,7 @@
package br.com.stackpanel.duck_api.service;
public interface RabbitPublisherService {
void sendNotificationCad(String notificationCad);
}

View File

@@ -0,0 +1,24 @@
package br.com.stackpanel.duck_api.service.impl;
import br.com.stackpanel.duck_api.service.RabbitPublisherService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import static br.com.stackpanel.duck_api.entity.enums.QueueNames.QUEUE_NOTIFICATION_ERROR;
public class RabbitPublisherServiceImpl implements RabbitPublisherService {
private static final Logger log = LoggerFactory.getLogger(RabbitPublisherServiceImpl.class);
private final RabbitTemplate rabbitTemplate;
public RabbitPublisherServiceImpl(RabbitTemplate rabbitTemplate) {
this.rabbitTemplate = rabbitTemplate;
}
@Override
public void sendNotificationCad(String notificationCad) {
log.info("Sending notification Cad: {}", notificationCad);
rabbitTemplate.convertAndSend(QUEUE_NOTIFICATION_ERROR.label, notificationCad);
}
}

View File

@@ -5,4 +5,10 @@ spring.datasource.password=${db_pass}
spring.datasource.username=${db_user} spring.datasource.username=${db_user}
spring.datasource.driver-class-name=org.postgresql.Driver spring.datasource.driver-class-name=org.postgresql.Driver
spring.jpa.hibernate.ddl-auto=update spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true spring.jpa.show-sql=true
spring.rabbitmq.host=rabbit.stackpanel.com.br
spring.rabbitmq.port=5672
spring.rabbitmq.username=${rabbit_username}
spring.rabbitmq.password=${rabbit_password}

View File

@@ -4,3 +4,9 @@ spring.datasource.url=${db_host:jdbc:postgresql://db.stackpanel.com.br:5432/nexu
spring.datasource.password=${db_pass} spring.datasource.password=${db_pass}
spring.datasource.username=${db_user} spring.datasource.username=${db_user}
spring.datasource.driver-class-name=org.postgresql.Driver spring.datasource.driver-class-name=org.postgresql.Driver
spring.rabbitmq.host=rabbit.stackpanel.com.br
spring.rabbitmq.port=5672
spring.rabbitmq.username=${rabbit_username}
spring.rabbitmq.password=${rabbit_password}