Skip to content

Commit

Permalink
Merge pull request #154 from bancolombia/feature/jms-mq
Browse files Browse the repository at this point in the history
Feature/jms mq
  • Loading branch information
dbuos authored Jul 7, 2021
2 parents 0191c10 + bf773e1 commit 6492865
Show file tree
Hide file tree
Showing 39 changed files with 1,260 additions and 33 deletions.
28 changes: 15 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,19 +177,20 @@ The Scaffolding Clean Architecture plugin will allow you run 8 tasks:
gradle gda --type [drivenAdapterType]
```

| Reference for **drivenAdapterType** | Name | Additional Options |
|-------------------------------------|-----------------------------|----------------------------------------------------|
| generic | Empty Driven Adapter | --name [name] |
| jpa | JPA Repository | --secret [true-false] |
| mongodb | Mongo Repository | --secret [true-false] |
| asynceventbus | Async Event Bus | |
| restconsumer | Rest Client Consumer | --url [url] |
| redis | Redis | --mode [template-repository] --secret [true-false] |
| rsocket | Rsocket Requester | |
| r2dbc | R2dbc Postgresql Client | |
| kms | AWS Key Management Service | |
| secrets | Secrets Manager Bancolombia | |
| s3 | AWS Simple Storage Service | |
| Reference for **drivenAdapterType** | Name | Additional Options |
|-------------------------------------|--------------------------------|----------------------------------------------------|
| generic | Empty Driven Adapter | --name [name] |
| jpa | JPA Repository | --secret [true-false] |
| mongodb | Mongo Repository | --secret [true-false] |
| asynceventbus | Async Event Bus | |
| restconsumer | Rest Client Consumer | --url [url] |
| redis | Redis | --mode [template-repository] --secret [true-false] |
| rsocket | RSocket Requester | |
| r2dbc | R2dbc Postgresql Client | |
| kms | AWS Key Management Service | |
| secrets | Secrets Manager Bancolombia | |
| s3 | AWS Simple Storage Service | |
| mq | JMS MQ Client to send messages | |

_**This task will generate something like that:**_

Expand Down Expand Up @@ -234,6 +235,7 @@ The Scaffolding Clean Architecture plugin will allow you run 8 tasks:
| rsocket | Rsocket Controller Entry Point | |
| graphql | API GraphQL | --pathgql [name path] default /graphql |
| asynceventhandler | Async Event Handler | |
| mq | JMS MQ Client to listen messages | |

Additionally, if you'll use a restmvc, you can specify the web server on which the application will run. By default, undertow.

Expand Down
21 changes: 3 additions & 18 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
if "%ERRORLEVEL%" == "0" goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Expand All @@ -54,7 +54,7 @@ goto fail
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto init
if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
Expand All @@ -64,29 +64,14 @@ echo location of your Java installation.

goto fail

:init
@rem Get command-line arguments, handling Windows variants

if not "%OS%" == "Windows_NT" goto win9xME_args

:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2

:win9xME_args_slurp
if "x%~1" == "x" goto execute

set CMD_LINE_ARGS=%*

:execute
@rem Setup the command line

set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar


@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*

:end
@rem End local scope for the variables with windows NT shell
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,61 @@ public void validateStructureReactiveWithInvalidUseCase() throws IOException {
runner.build();
}

@Test
public void shouldGenerateMQEntryPoint() {
canRunTaskGenerateStructureReactiveProject();
String task = "generateEntryPoint";
String type = "MQ";

runner.withArguments(task, "--type=" + type);
runner.withProjectDir(projectDir);
BuildResult result = runner.build();

assertTrue(
new File("build/functionalTest/infrastructure/entry-points/mq-listener/build.gradle")
.exists());
assertTrue(
new File(
"build/functionalTest/infrastructure/entry-points/mq-listener/src/main/java/co/com/bancolombia/mq/listener/SampleMQMessageListener.java")
.exists());
validateMQCommon();
assertEquals(result.task(":" + task).getOutcome(), TaskOutcome.SUCCESS);
}

@Test
public void shouldGenerateMQDrivenAdapter() {
canRunTaskGenerateStructureReactiveProject();
String task = "generateDrivenAdapter";
String type = "MQ";

runner.withArguments(task, "--type=" + type);
runner.withProjectDir(projectDir);
BuildResult result = runner.build();

assertTrue(
new File("build/functionalTest/infrastructure/driven-adapters/mq-sender/build.gradle")
.exists());
assertTrue(
new File(
"build/functionalTest/infrastructure/driven-adapters/mq-sender/src/main/java/co/com/bancolombia/mq/sender/SampleMQMessageSender.java")
.exists());
validateMQCommon();
assertEquals(result.task(":" + task).getOutcome(), TaskOutcome.SUCCESS);
}

private void validateMQCommon() {
assertTrue(
new File("build/functionalTest/infrastructure/helpers/mq-common/build.gradle").exists());
assertTrue(
new File(
"build/functionalTest/infrastructure/helpers/mq-common/src/main/java/co/com/bancolombia/mq/common/MQReactiveMessageListener.java")
.exists());
assertTrue(
new File(
"build/functionalTest/infrastructure/helpers/mq-common/src/main/java/co/com/bancolombia/mq/common/api/MQMessageSender.java")
.exists());
}

private void writeString(File file, String string) throws IOException {
try (Writer writer = new FileWriter(file)) {
writer.write(string);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/co/com/bancolombia/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class Constants {
public static final String GRADLE_WRAPPER_VERSION = "6.7";
public static final String TOMCAT_EXCLUSION =
"compile.exclude group: \"org.springframework.boot\", module:\"spring-boot-starter-tomcat\"";
public static final String MQ_CLIENT_VERSION = "2.5.0";

public enum BooleanOption {
TRUE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public ModuleBuilder(Project project) {
params.put("objectMapperVersion", Constants.RCOMMONS_OBJECT_MAPPER_VERSION);
params.put("coberturaVersion", Constants.COBERTURA_VERSION);
params.put("lombokVersion", Constants.LOMBOK_VERSION);
params.put("mqVersion", Constants.MQ_CLIENT_VERSION);
try {
loadPackage();
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package co.com.bancolombia.factory.adapters;

import co.com.bancolombia.exceptions.CleanException;
import co.com.bancolombia.factory.ModuleBuilder;
import co.com.bancolombia.factory.ModuleFactory;
import co.com.bancolombia.factory.commons.MQCommonFactory;
import co.com.bancolombia.factory.validations.ReactiveTypeValidation;
import java.io.IOException;
import lombok.AllArgsConstructor;

@AllArgsConstructor
public class DrivenAdapterMQ implements ModuleFactory {

@Override
public void buildModule(ModuleBuilder builder) throws IOException, CleanException {
builder.runValidations(ReactiveTypeValidation.class);
builder.setupFromTemplate("driven-adapter/mq-sender");
builder.appendToSettings("mq-sender", "infrastructure/driven-adapters");
builder.appendDependencyToModule("app-service", "implementation project(':mq-sender')");
new MQCommonFactory().buildModule(builder);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public static ModuleFactory getDrivenAdapterFactory(DrivenAdapterType type)
return new DrivenAdapterKms();
case SECRETS:
return new DrivenAdapterSecrets();
case MQ:
return new DrivenAdapterMQ();
default:
throw new InvalidTaskOptionException("Driven Adapter type invalid");
}
Expand All @@ -46,6 +48,7 @@ public enum DrivenAdapterType {
R2DBC,
KMS,
SECRETS,
S3
S3,
MQ
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package co.com.bancolombia.factory.commons;

import co.com.bancolombia.exceptions.CleanException;
import co.com.bancolombia.factory.ModuleBuilder;
import co.com.bancolombia.factory.ModuleFactory;
import java.io.IOException;

public class MQCommonFactory implements ModuleFactory {

@Override
public void buildModule(ModuleBuilder builder) throws IOException, CleanException {
builder.setupFromTemplate("commons/mq-common");
builder
.appendToProperties("ibm")
.put("output-concurrency", 10)
.put("output-queue", "DEV.QUEUE.1")
.put("input-concurrency", 10)
.put("input-queue", "DEV.QUEUE.2");
builder.appendToProperties("ibm.mq").put("channel", "DEV.APP.SVRCONN").put("user", "app");
builder.appendToSettings("mq-common", "infrastructure/helpers");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package co.com.bancolombia.factory.entrypoints;

import co.com.bancolombia.exceptions.CleanException;
import co.com.bancolombia.factory.ModuleBuilder;
import co.com.bancolombia.factory.ModuleFactory;
import co.com.bancolombia.factory.commons.MQCommonFactory;
import co.com.bancolombia.factory.validations.ReactiveTypeValidation;
import java.io.IOException;

public class EntryPointMQ implements ModuleFactory {

@Override
public void buildModule(ModuleBuilder builder) throws IOException, CleanException {
builder.runValidations(ReactiveTypeValidation.class);
builder.setupFromTemplate("entry-point/mq-listener");
builder.appendToSettings("mq-listener", "infrastructure/entry-points");
builder.appendDependencyToModule("app-service", "implementation project(':mq-listener')");
new MQCommonFactory().buildModule(builder);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public static ModuleFactory getEntryPointFactory(EntryPointType type)
return new EntryPointGraphql();
case ASYNCEVENTHANDLER:
return new EntryPointAsyncEventHandler();
case MQ:
return new EntryPointMQ();
default:
throw new InvalidTaskOptionException("Entry Point type invalid");
}
Expand All @@ -31,6 +33,7 @@ public enum EntryPointType {
GENERIC,
RSOCKET,
GRAPHQL,
ASYNCEVENTHANDLER
ASYNCEVENTHANDLER,
MQ
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package {{package}}.mq.common.api;

import javax.jms.Destination;
import javax.jms.JMSContext;

public interface MQDestinationProvider {
Destination create(JMSContext context);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package {{package}}.mq.common.api;

import javax.jms.JMSContext;
import javax.jms.JMSException;
import javax.jms.Message;

public interface MQMessageCreator {
Message create(JMSContext context) throws JMSException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package {{package}}.mq.common.api;

import reactor.core.publisher.Mono;

import javax.jms.Destination;

public interface MQMessageSender {
Mono<String> send(Destination destination, MQMessageCreator messageCreator);
Mono<String> send(MQMessageCreator messageCreator);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package {{package}}.mq.common.api;

import javax.jms.TemporaryQueue;

public interface MQTemporaryQueuesContainer {
void registerTemporaryQueue(String alias, TemporaryQueue queue);
TemporaryQueue get(String alias);
}
4 changes: 4 additions & 0 deletions src/main/resources/commons/mq-common/build.gradle.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dependencies {
compile 'org.springframework:spring-context'
compile 'com.ibm.mq:mq-jms-spring-boot-starter:{{mqVersion}}'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package {{package}}.mq.common.config.exceptions;

public class MQInvalidListenerSetup extends RuntimeException {
public MQInvalidListenerSetup(String message) {
super(message);
}
}
Loading

0 comments on commit 6492865

Please sign in to comment.