-
Notifications
You must be signed in to change notification settings - Fork 50
Template command
José Vieira Neto edited this page Jul 14, 2019
·
3 revisions
The template command is intended to configure libs/frameworks
in an existing spring boot project very quickly and easily.
command | argument | goal |
---|---|---|
spring template | --list | list all templates avaliable |
spring template | -t ${TEMPLATE_NAME} | apply template in your project |
-
jms-aws-sqs
CREATED src/main/java/com/example/cloudawsmessaging/consumer/MessageListener.java
public interface MessageListener { void queueListener(String String); }
CREATED src/main/java/com/example/cloudawsmessaging/consumer/EntryPointMessage.java
public class EntryPointMessage implements MessageListener { private static final Logger log = LogManager.getLogger(EntryPointMessage.class); @Override @SqsListener(value = "${cloud.aws.sqs.queue-name}", deletionPolicy = SqsMessageDeletionPolicy.ON_SUCCESS) public void queueListener(String String) { } }
CREATED src/main/java/com/example/cloudawsmessaging/consumer/ProducerMessage.java
@Component public class ProducerMessage { @Value("${cloud.aws.sqs.queue-name}") private String queueName; private QueueMessagingTemplate queueMessagingTemplate; @Autowired public ProducerMessage(AmazonSQSAsync amazonSqs) { this.queueMessagingTemplate = new QueueMessagingTemplate(amazonSqs); } public void sendMessage() { this.queueMessagingTemplate.convertAndSend(queueName, "YOUR_MESSAGE_OBJECT", getHeader()); } private Map<String, Object> getHeader() { Map<String, Object> headers = new HashMap<>(); headers.put(SqsMessageHeaders.SQS_GROUP_ID_HEADER, UUID.randomUUID().toString()); headers.put(SqsMessageHeaders.SQS_DEDUPLICATION_ID_HEADER, UUID.randomUUID().toString()); headers.put(SqsMessageHeaders.CONTENT_TYPE, "application/json"); return headers; } }
Add dependencies in pom.xml
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-aws-messaging</artifactId> <version>2.1.1.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-aws</artifactId> <version>2.1.1.RELEASE</version> </dependency>
Add properties in application.properties
cloud.aws.credentials.accessKey=xxxxxx cloud.aws.credentials.secretKey=xxxxxx cloud.aws.region.static=us-east-1 cloud.aws.stack.auto=false cloud.aws.sqs.queue-name=my-queue.fifo
-
openj9
CREATED openj9-template-sample\deploy\Dockerfile
FROM adoptopenjdk/openjdk8-openj9 RUN mkdir /opt/shareclasses RUN mkdir /opt/app ADD ../target/*.jar /opt/app.jar EXPOSE 8080 CMD ["java", "-Xmx512m", "-XX:+IdleTuningGcOnIdle", "-Xtune:virtualized", "-Xscmx512m", "-Xscmaxaot100m", "- Xshareclasses:cacheDir=/opt/shareclasses", "-jar", "/opt/app.jar"]
Add maven plugin in pom.xml
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>2.4.3</version> <dependencies <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>2.1.5.RELEASE</version> </dependency> </dependencies> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <transformers> <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> <resource>META-INF/spring.handlers</resource> </transformer> <transformer implementation="org.springframework.boot.maven.PropertiesMergingResourceTransformer"> <resource>META-INF/spring.factories</resource> </transformer> <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> <resource>META-INF/spring.schemas</resource> </transformer> <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/> <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> <mainClass>com.example.cloudawsmessaging.DemoApplication</mainClass> </transformer> </transformers> </configuration> </execution> </executions> <configuration> <createDependencyReducedPom>false</createDependencyReducedPom> </configuration> </plugin>