Skip to content

Commit

Permalink
Merge pull request #65 from TC4Y-777/stage
Browse files Browse the repository at this point in the history
Add RabbitMQ broker
  • Loading branch information
getwithashish authored Sep 13, 2023
2 parents ea5c539 + 35a2a5f commit bcf9330
Show file tree
Hide file tree
Showing 68 changed files with 5,127 additions and 148 deletions.
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,22 @@ Web application for storing tithe information.

For local deployment:

1. Install docker and docker-compose
1. Install docker and docker compose

2. Run: docker-compose up
2. Run: docker compose --profile dev up

3. Test GraphQL queries and mutations on: http://localhost:8080/graphiql

4. Test Frontend on: http://localhost/#/dashboard
4. Test Frontend on: http://localhost:5173/#/dashboard

## Stage Deployment

For stage deployment:

1. Install docker and docker compose

2. Run: docker compose --profile stage up

3. Test GraphQL queries and mutations on: http://ip-of-server:8080/graphiql

4. Test Frontend on: http://ip-of-server:4173/#/dashboard
2 changes: 2 additions & 0 deletions Tithe-Spring/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-graphql'
implementation("com.tailrocks.graphql:graphql-datetime-spring-boot-starter:6.0.0")
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-amqp'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'org.postgresql:postgresql'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework:spring-webflux'
testImplementation 'org.springframework.graphql:spring-graphql-test'
testImplementation 'org.springframework.amqp:spring-rabbit-test'
}

tasks.named('test') {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.tithe.client.rabbitmq.consumer;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Service;

import com.tithe.entity.RelationEntity;

@Service
public class TempConsumer {

private static final Logger LOGGER = LoggerFactory.getLogger(TempConsumer.class);

@RabbitListener(queues = {"tempQueue"})
public void consume(RelationEntity relation) {
LOGGER.info(String.format("Message Received: %s", relation));

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.tithe.client.rabbitmq.producer;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.tithe.entity.RelationEntity;

@Service
public class TempProducer {

private static final Logger LOGGER = LoggerFactory.getLogger(TempProducer.class);

@Autowired
private RabbitTemplate rabbitTemplate;

public void sendMessage(String message) {
RelationEntity relation = new RelationEntity(23L, "Niece");
LOGGER.info(String.format("Message sent: %s", relation));

rabbitTemplate.convertAndSend("tempTopicExchange", "tempQueueRoutingKey", relation);
}

}
56 changes: 56 additions & 0 deletions Tithe-Spring/src/main/java/com/tithe/config/RabbitMQConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
*
*/
package com.tithe.config;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
* @author Ashish Sam T George
*
*/
@Configuration
public class RabbitMQConfig {

@Bean
public Queue queue() {
return new Queue("tempQueue");
}


@Bean
public TopicExchange exchange() {
return new TopicExchange("tempTopicExchange");
}

@Bean
public Binding binding() {
return BindingBuilder
.bind(queue())
.to(exchange())
.with("tempQueueRoutingKey");
}

@Bean
public MessageConverter converter() {
return new Jackson2JsonMessageConverter();
}

@Bean
public AmqpTemplate amqpTemplate(ConnectionFactory connectionFactory) {
RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);
rabbitTemplate.setMessageConverter(converter());
return rabbitTemplate;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.springframework.graphql.data.method.annotation.QueryMapping;
import org.springframework.stereotype.Controller;

import com.tithe.client.rabbitmq.producer.TempProducer;
import com.tithe.entity.EducationEntity;
import com.tithe.entity.FamilyEntity;
import com.tithe.entity.OccupationEntity;
Expand All @@ -38,6 +39,9 @@ public class PersonController {

@Autowired
private TitheRepository titheRepository;

@Autowired
private TempProducer tempProducer;

@QueryMapping
public PersonEntity getPerson() {
Expand Down Expand Up @@ -92,5 +96,12 @@ public TempEntity testMutation(@Argument TempInput time) {
tempEntity.setTimeStamp(LocalDate.parse(time.getTimeStamp()));
return tempRepo.save(tempEntity);
}

@MutationMapping
public RelationEntity tempPublishToRabbit(@Argument String message) {
tempProducer.sendMessage(message);
RelationEntity relation = new RelationEntity(23L, "Niece");
return relation;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.springframework.stereotype.Controller;

import com.tithe.entity.FamilyEntity;
import com.tithe.entity.KoottaymaEntity;
import com.tithe.model.FamilyMutationInput;
import com.tithe.service.mutation.FamilyMutationService;

Expand All @@ -26,5 +27,15 @@ public class FamilyMutations {
public FamilyEntity createOneFamily(@Argument(name = "family") FamilyMutationInput familyMutationInput) {
return familyMutationService.createOneFamily(familyMutationInput);
}

@MutationMapping(name = "activateOneFamily")
public FamilyEntity activateOneFamily(@Argument(name = "familyId") Long familyId) {
return familyMutationService.activateOneFamily(familyId);
}

@MutationMapping(name = "deactivateOneFamily")
public FamilyEntity deactivateOneFamily(@Argument(name = "familyId") Long familyId) {
return familyMutationService.deactivateOneFamily(familyId);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,15 @@ public class ForaneMutations {
public ForaneEntity createOneForane(@Argument(name = "forane") ForaneMutationInput foraneMutationInput) {
return foraneMutationService.createOneForane(foraneMutationInput);
}

@MutationMapping(name = "activateOneForane")
public ForaneEntity activateOneForane(@Argument(name = "foraneId") Long foraneId) {
return foraneMutationService.activateOneForane(foraneId);
}

@MutationMapping(name = "deactivateOneForane")
public ForaneEntity deactivateOneForane(@Argument(name = "foraneId") Long foraneId) {
return foraneMutationService.deactivateOneForane(foraneId);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.springframework.stereotype.Controller;

import com.tithe.entity.KoottaymaEntity;
import com.tithe.entity.ParishEntity;
import com.tithe.model.KoottaymaMutationInput;
import com.tithe.service.mutation.KoottaymaMutationService;

Expand All @@ -26,5 +27,15 @@ public class KoottaymaMutations {
public KoottaymaEntity createOneKoottayma(@Argument(name = "koottayma") KoottaymaMutationInput koottaymaMutationInput) {
return koottaymaMutationService.createOneKoottayma(koottaymaMutationInput);
}

@MutationMapping(name = "activateOneKoottayma")
public KoottaymaEntity activateOneKoottayma(@Argument(name = "koottaymaId") Long koottaymaId) {
return koottaymaMutationService.activateOneKoottayma(koottaymaId);
}

@MutationMapping(name = "deactivateOneKoottayma")
public KoottaymaEntity deactivateOneKoottayma(@Argument(name = "koottaymaId") Long koottaymaId) {
return koottaymaMutationService.deactivateOneKoottayma(koottaymaId);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.springframework.graphql.data.method.annotation.MutationMapping;
import org.springframework.stereotype.Controller;

import com.tithe.entity.ForaneEntity;
import com.tithe.entity.ParishEntity;
import com.tithe.model.ParishMutationInput;
import com.tithe.service.mutation.ParishMutationService;
Expand All @@ -26,5 +27,15 @@ public class ParishMutations {
public ParishEntity createOneParish(@Argument(name = "parish") ParishMutationInput parishMutationInput) {
return parishMutationService.createOneParish(parishMutationInput);
}

@MutationMapping(name = "activateOneParish")
public ParishEntity activateOneParish(@Argument(name = "parishId") Long parishId) {
return parishMutationService.activateOneParish(parishId);
}

@MutationMapping(name = "deactivateOneParish")
public ParishEntity deactivateOneParish(@Argument(name = "parishId") Long parishId) {
return parishMutationService.deactivateOneParish(parishId);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ public List<AddressEntity> getAllAddresses(){
public StreetEntity getOneStreet(@Argument Long id) {
return addressQueryService.getOneStreet(id);
}

@QueryMapping(name = "getSimilarStreets")
public List<StreetEntity> getSimilarStreets(@Argument(name = "streetName") String streetName){
if (streetName==null || streetName.isBlank()) {
return null;
}
return addressQueryService.getSimilarStreets(streetName);
}

@QueryMapping(name = "getAllStreets")
public List<StreetEntity> getAllStreets(){
Expand All @@ -58,6 +66,14 @@ public List<StreetEntity> getAllStreets(){
public CityEntity getOneCity(@Argument Long id) {
return addressQueryService.getOneCity(id);
}

@QueryMapping(name = "getSimilarCities")
public List<CityEntity> getSimilarCities(@Argument(name = "cityName") String cityName){
if (cityName==null || cityName.isBlank()) {
return null;
}
return addressQueryService.getSimilarCities(cityName);
}

@QueryMapping(name = "getAllCities")
public List<CityEntity> getAllCities(){
Expand All @@ -68,6 +84,14 @@ public List<CityEntity> getAllCities(){
public DistrictEntity getOneDistrict(@Argument Long id) {
return addressQueryService.getOneDistrict(id);
}

@QueryMapping(name = "getSimilarDistricts")
public List<DistrictEntity> getSimilarDistricts(@Argument(name = "districtName") String districtName){
if (districtName==null || districtName.isBlank()) {
return null;
}
return addressQueryService.getSimilarDistricts(districtName);
}

@QueryMapping(name = "getAllDistricts")
public List<DistrictEntity> getAllDistricts(){
Expand All @@ -78,6 +102,14 @@ public List<DistrictEntity> getAllDistricts(){
public StateEntity getOneState(@Argument Long id) {
return addressQueryService.getOneState(id);
}

@QueryMapping(name = "getSimilarStates")
public List<StateEntity> getSimilarStates(@Argument(name = "stateName") String stateName){
if (stateName==null || stateName.isBlank()) {
return null;
}
return addressQueryService.getSimilarStates(stateName);
}

@QueryMapping(name = "getAllStates")
public List<StateEntity> getAllStates(){
Expand All @@ -88,6 +120,14 @@ public List<StateEntity> getAllStates(){
public PincodeEntity getOnePincode(@Argument Long id) {
return addressQueryService.getOnePincode(id);
}

@QueryMapping(name = "getSimilarPincodes")
public List<PincodeEntity> getSimilarPincodes(@Argument(name = "pincode") String pincode){
if (pincode==null || pincode.isBlank()) {
return null;
}
return addressQueryService.getSimilarPincodes(pincode);
}

@QueryMapping(name = "getAllPincodes")
public List<PincodeEntity> getAllPincodes(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,45 @@ public FamilyEntity getOneFamily(@Argument Long id) {
public List<FamilyEntity> getManyFamilies(@Argument(name = "filter") FamilyQueryFilter familyQueryFilter){
return familyQueryService.getManyFamilies(familyQueryFilter);
}

@QueryMapping(name = "getAllFamilies")
public List<FamilyEntity> getAllFamilies(){
return familyQueryService.getAllFamilies();
}

@QueryMapping(name = "getAllFamiliesByForane")
public List<FamilyEntity> getAllFamiliesByForane(@Argument(name = "foraneId") Long foraneId){
return familyQueryService.getAllFamiliesByForane(foraneId);
}

@QueryMapping(name = "getAllFamiliesByParish")
public List<FamilyEntity> getAllFamiliesByParish(@Argument(name = "parishId") Long parishId){
return familyQueryService.getAllFamiliesByParish(parishId);
}

@QueryMapping(name = "getAllFamiliesByKoottayma")
public List<FamilyEntity> getAllFamiliesByKoottayma(@Argument(name = "koottaymaId") Long koottaymaId){
return familyQueryService.getAllFamiliesByKoottayma(koottaymaId);
}

@QueryMapping(name = "getFamilyCount")
public Long getFamilyCount() {
return familyQueryService.getFamilyCount();
}

@QueryMapping(name = "getFamilyCountByForane")
public Long getFamilyCountByForane(@Argument(name = "foraneId") Long foraneId) {
return familyQueryService.getFamilyCountByForane(foraneId);
}

@QueryMapping(name = "getFamilyCountByParish")
public Long getFamilyCountByParish(@Argument(name = "parishId") Long parishId) {
return familyQueryService.getFamilyCountByParish(parishId);
}

@QueryMapping(name = "getFamilyCountByKoottayma")
public Long getFamilyCountByKoottayma(@Argument(name = "koottaymaId") Long koottaymaId) {
return familyQueryService.getFamilyCountByKoottayma(koottaymaId);
}

}
Loading

0 comments on commit bcf9330

Please sign in to comment.