From bc2cf43aaa5469b0e4ab567c9a54d8d2726eaa6e Mon Sep 17 00:00:00 2001 From: MarioKusek Date: Fri, 30 Mar 2018 13:37:07 +0200 Subject: [PATCH 1/2] Refactored creation of RabbitManager --- build.gradle | 8 ++++---- .../rapplugin/rap/plugin/RapPluginRegistrationTest.java | 8 ++++++-- .../h2020/symbiote/rapplugin/RapPluginConfiguration.java | 8 ++++++++ .../h2020/symbiote/rapplugin/messaging/RabbitManager.java | 1 - 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/build.gradle b/build.gradle index 0ab4231..d8e5650 100644 --- a/build.gradle +++ b/build.gradle @@ -7,6 +7,7 @@ buildscript { } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") + classpath group: 'com.cinnober.gradle', name: 'semver-git', version: '2.3.1' } } @@ -27,14 +28,14 @@ plugins { id "maven-publish" } +apply plugin: 'com.cinnober.gradle.semver-git' + group = 'eu.h2020.symbiote' -version = '0.3.1' // this is needed for starter to not create fat jar bootRepackage.enabled = false jar { - baseName = 'rap-plugin' version = project.version } @@ -100,14 +101,13 @@ dependencies { dependencyManagement { imports { - mavenBom "org.springframework.cloud:spring-cloud-dependencies:Dalston.SR2" + mavenBom "org.springframework.cloud:spring-cloud-dependencies:Dalston.SR5" } } // creating source jar task sourceJar(type: Jar) { from sourceSets.main.allJava - baseName = 'rap-plugin' version = project.version } diff --git a/src/integration-test/java/eu/h2020/symbiote/rapplugin/rap/plugin/RapPluginRegistrationTest.java b/src/integration-test/java/eu/h2020/symbiote/rapplugin/rap/plugin/RapPluginRegistrationTest.java index bda8068..0646882 100644 --- a/src/integration-test/java/eu/h2020/symbiote/rapplugin/rap/plugin/RapPluginRegistrationTest.java +++ b/src/integration-test/java/eu/h2020/symbiote/rapplugin/rap/plugin/RapPluginRegistrationTest.java @@ -40,8 +40,7 @@ import eu.h2020.symbiote.rapplugin.TestingRabbitConfig; @RunWith(SpringRunner.class) -@Import({RabbitManager.class, - TestingRabbitConfig.class, +@Import({TestingRabbitConfig.class, RapPluginProperties.class}) @EnableConfigurationProperties({RabbitConnectionProperties.class, RapProperties.class}) @DirtiesContext @@ -59,6 +58,11 @@ public static class TestConfiguration { public RapPlugin rapPlugin(RabbitManager manager) { return new RapPlugin(manager, "platId", false, true); } + + @Bean + public RabbitManager rapRabbitManager(RabbitTemplate template) { + return new RabbitManager(template); + } } @Autowired diff --git a/src/main/java/eu/h2020/symbiote/rapplugin/RapPluginConfiguration.java b/src/main/java/eu/h2020/symbiote/rapplugin/RapPluginConfiguration.java index 2deffd3..688e6af 100644 --- a/src/main/java/eu/h2020/symbiote/rapplugin/RapPluginConfiguration.java +++ b/src/main/java/eu/h2020/symbiote/rapplugin/RapPluginConfiguration.java @@ -7,15 +7,18 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory; +import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter; import org.springframework.beans.BeansException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; +import eu.h2020.symbiote.rapplugin.messaging.RabbitManager; import eu.h2020.symbiote.rapplugin.properties.RabbitConnectionProperties; import eu.h2020.symbiote.rapplugin.properties.RapProperties; @@ -28,6 +31,11 @@ public class RapPluginConfiguration implements ApplicationContextAware { private static final Logger LOG = LoggerFactory.getLogger(RapPluginConfiguration.class); + @Bean + public RabbitManager rapRabbitManager(RabbitTemplate template) { + return new RabbitManager(template); + } + @Autowired private SimpleRabbitListenerContainerFactory simpleRabbitListenerContainerFactory; diff --git a/src/main/java/eu/h2020/symbiote/rapplugin/messaging/RabbitManager.java b/src/main/java/eu/h2020/symbiote/rapplugin/messaging/RabbitManager.java index 8fc53a2..b0435a6 100644 --- a/src/main/java/eu/h2020/symbiote/rapplugin/messaging/RabbitManager.java +++ b/src/main/java/eu/h2020/symbiote/rapplugin/messaging/RabbitManager.java @@ -23,7 +23,6 @@ * * @author mateuszl, Petar Krivic, Mario Kusek */ -@Component public class RabbitManager { private static final Logger LOG = LoggerFactory.getLogger(RabbitManager.class); private static final int REPLY_TIMEOUT = 20_000; From 96aa22ba8ad854425efd5d8cd0e21113e6ce364a Mon Sep 17 00:00:00 2001 From: MarioKusek Date: Wed, 4 Apr 2018 07:47:10 +0200 Subject: [PATCH 2/2] Update so it can be used in other starters --- .../symbiote/rapplugin/RapPluginConfiguration.java | 14 +++++++++++++- .../rapplugin/messaging/rap/RapPlugin.java | 1 - .../rapplugin/properties/RapPluginProperties.java | 1 - 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/java/eu/h2020/symbiote/rapplugin/RapPluginConfiguration.java b/src/main/java/eu/h2020/symbiote/rapplugin/RapPluginConfiguration.java index 688e6af..8038801 100644 --- a/src/main/java/eu/h2020/symbiote/rapplugin/RapPluginConfiguration.java +++ b/src/main/java/eu/h2020/symbiote/rapplugin/RapPluginConfiguration.java @@ -17,14 +17,16 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; +import org.springframework.stereotype.Component; import eu.h2020.symbiote.rapplugin.messaging.RabbitManager; +import eu.h2020.symbiote.rapplugin.messaging.rap.RapPlugin; import eu.h2020.symbiote.rapplugin.properties.RabbitConnectionProperties; +import eu.h2020.symbiote.rapplugin.properties.RapPluginProperties; import eu.h2020.symbiote.rapplugin.properties.RapProperties; @Configuration -@ComponentScan(basePackages = {"eu.h2020.symbiote.rapplugin"}) @EnableConfigurationProperties({ RabbitConnectionProperties.class, RapProperties.class}) @@ -36,6 +38,16 @@ public RabbitManager rapRabbitManager(RabbitTemplate template) { return new RabbitManager(template); } + @Bean + public RapPlugin rapPlugin(RabbitManager manager, RapPluginProperties props) { + return new RapPlugin(manager, props); + } + + @Bean + public RapPluginProperties rapPluginProperties(RabbitConnectionProperties rabbitConnection, RapProperties pluginProperties) { + return new RapPluginProperties(rabbitConnection, pluginProperties); + } + @Autowired private SimpleRabbitListenerContainerFactory simpleRabbitListenerContainerFactory; diff --git a/src/main/java/eu/h2020/symbiote/rapplugin/messaging/rap/RapPlugin.java b/src/main/java/eu/h2020/symbiote/rapplugin/messaging/rap/RapPlugin.java index 45c0bae..0583ef3 100644 --- a/src/main/java/eu/h2020/symbiote/rapplugin/messaging/rap/RapPlugin.java +++ b/src/main/java/eu/h2020/symbiote/rapplugin/messaging/rap/RapPlugin.java @@ -60,7 +60,6 @@ * @author Mario Kušek * */ -@Service public class RapPlugin implements SmartLifecycle { private static final Logger LOG = LoggerFactory.getLogger(RapPlugin.class); diff --git a/src/main/java/eu/h2020/symbiote/rapplugin/properties/RapPluginProperties.java b/src/main/java/eu/h2020/symbiote/rapplugin/properties/RapPluginProperties.java index 1123f64..5b9617f 100644 --- a/src/main/java/eu/h2020/symbiote/rapplugin/properties/RapPluginProperties.java +++ b/src/main/java/eu/h2020/symbiote/rapplugin/properties/RapPluginProperties.java @@ -12,7 +12,6 @@ * @author Mario Kušek * */ -@Component("rapPluginProperties") public class RapPluginProperties { /** * The name of RAP plugin.