Skip to content

Commit

Permalink
Merge pull request #11 from Ar3secchim/feature/configuration-queue
Browse files Browse the repository at this point in the history
Feature/configuration queue
  • Loading branch information
Ar3secchim committed Nov 25, 2023
2 parents 88abba0 + 2f7e6af commit b5b99d3
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 11 deletions.
10 changes: 5 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ services:

rabbit:
image: rabbitmq:3-management
container_name: rabbitmq_service_package
container_name: rabbitmq_service_subscription
ports:
- 5672:5672 # (erlang) communication between the nodes and CLI tool
- 15672:15672 # communication with the web management API
- 5672:5672 # (erlang) communication between the nodes and CLI tool
- 15672:15672 # communication with the web management API
environment:
- RABBITMQ_DEFAULT_USER=subscription
- RABBITMQ_DEFAULT_PASS=subscription
- RABBITMQ_DEFAULT_USER=subscription
- RABBITMQ_DEFAULT_PASS=subscription
restart: always
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ public Queue queue(){
return new Queue(queueSubs, true);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package ada.tech.tenthirty.tvpackages.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Value;

@Configuration
public class TechnicalVisitQueue {
@Value("${config.technical-visit.queue.out}")
private String queue;

@Bean
public Queue queue(){
return new Queue(queue, true);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package ada.tech.tenthirty.tvpackages.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.function.client.WebClient;


@Configuration
public class WebClientConfig<StockClient> {
@Value("${config.subscription-package.url}")
private String subscriptionUrl;

@Value("${config.technical-visit.url}")
private String technicalVisitUrl;

@Bean
WebClient webClient(){
return WebClient.builder().baseUrl(subscriptionUrl)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package ada.tech.tenthirty.tvpackages.queue;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service;
import org.springframework.amqp.core.Queue;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import ada.tech.tenthirty.tvpackages.queue.payloads.NotifyInvoiceRequest;
import lombok.RequiredArgsConstructor;

@Service
@RequiredArgsConstructor
public class NotifyInvoiceProducer {
private final RabbitTemplate rabbitTemplate;
private final Queue queue;
private final ObjectMapper objectMapper;

public void execute (NotifyInvoiceRequest notifyInvoice) throws JsonProcessingException {
String message = objectMapper.writeValueAsString(notifyInvoice);
rabbitTemplate.convertSendAndReceive(queue.getName(), message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package ada.tech.tenthirty.tvpackages.queue;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service;
import org.springframework.amqp.core.Queue;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import ada.tech.tenthirty.tvpackages.queue.payloads.ScheduleTechnicalVisitRequest;
import lombok.RequiredArgsConstructor;

@Service
@RequiredArgsConstructor
public class ScheduleTechnicalVisitProducer {
private final RabbitTemplate rabbitTemplate;
private final Queue queue;
private final ObjectMapper objectMapper;

public void execute(ScheduleTechnicalVisitRequest ScheduleTechnicalVisit) throws JsonProcessingException {
String message = objectMapper.writeValueAsString(ScheduleTechnicalVisit);
rabbitTemplate.convertSendAndReceive(queue.getName(), message);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package ada.tech.tenthirty.tvpackages.queue.payloads;
import java.time.LocalDateTime;
import java.util.List;

import lombok.Data;

@Data
public class NotifyInvoiceRequest {
private String idUser;
private LocalDateTime issueDate;
private List<Package> listPackage;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package ada.tech.tenthirty.tvpackages.queue.payloads;

import lombok.Data;

@Data
public class ScheduleTechnicalVisitRequest {
private String idUser;
private Boolean newUSer;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@
"type": "java.lang.String",
"description": "A description for 'spring.liquibase.changeLogFile'"
},
{
"name": "spring.config.technicalVisit.url",
"type": "java.lang.String",
"description": "A description for 'spring.config.technicalVisit.url'"
},
{
"name": "spring.config.technicalVisit.queue.out",
"type": "java.lang.String",
"description": "A description for 'spring.config.technicalVisit.queue.out'"
},
{
"name": "spring.config.subscription.url",
"type": "java.lang.String",
Expand All @@ -28,5 +38,14 @@
"name": "config.subscription-package.queue.out",
"type": "java.lang.String",
"description": "A description for 'config.subscriptionPackage.queue.out'"
}
]}
},
{
"name": "config.technical-visit.url",
"type": "java.lang.String",
"description": "A description for 'config.technical-visit.url'"
},
{
"name": "config.technical-visit.queue.out",
"type": "java.lang.String",
"description": "A description for 'config.technical-visit.queue.out'"

7 changes: 3 additions & 4 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ spring.rabbitmq.cache.connection.mode=CONNECTION
spring.rabbitmq.cache.channel.size=50

#Queue configuration

config.technical-visit.url= http://localhost:9081
config.technical-visit.queue.out= schedule_technical_visit
config.technical-visit.url=http://localhost:9081
config.technical-visit.queue.out=schedule_technical_visit

config.subscription-package.url= http://localhost:9081
config.subscription-package.queue.out= subscription-package
config.subscription-package.queue.out=out: shedule_technical_visit

0 comments on commit b5b99d3

Please sign in to comment.