activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From michaelpea...@apache.org
Subject [1/2] activemq-artemis git commit: ARTEMIS-2033 add spring-boot-integration example
Date Tue, 14 Aug 2018 22:46:05 GMT
Repository: activemq-artemis
Updated Branches:
  refs/heads/master 94e34febf -> dd15aa87d


ARTEMIS-2033 add spring-boot-integration example


Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/550c79b1
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/550c79b1
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/550c79b1

Branch: refs/heads/master
Commit: 550c79b1341462f0cb4721018451abeee414d9dc
Parents: 94e34fe
Author: Ricardo Zanini <ricardozanini@gmail.com>
Authored: Sun Aug 12 18:16:10 2018 -0300
Committer: Michael Andre Pearce <michael.andre.pearce@me.com>
Committed: Tue Aug 14 23:45:31 2018 +0100

----------------------------------------------------------------------
 examples/features/standard/pom.xml              |   1 +
 .../standard/spring-boot-integration/README.md  |   7 ++
 .../standard/spring-boot-integration/pom.xml    | 102 +++++++++++++++++++
 .../jms/example/springboot/Application.java     |  70 +++++++++++++
 .../jms/example/springboot/ExampleListener.java |  29 ++++++
 .../jms/example/springboot/MessageSender.java   |  41 ++++++++
 ...dditional-spring-configuration-metadata.json |  44 ++++++++
 .../src/main/resources/application.properties   |  23 +++++
 .../src/main/resources/broker.xml               |  42 ++++++++
 .../src/main/resources/logback.xml              |  38 +++++++
 10 files changed, 397 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/550c79b1/examples/features/standard/pom.xml
----------------------------------------------------------------------
diff --git a/examples/features/standard/pom.xml b/examples/features/standard/pom.xml
index 0493457..6ede897 100644
--- a/examples/features/standard/pom.xml
+++ b/examples/features/standard/pom.xml
@@ -94,6 +94,7 @@ under the License.
             <module>shared-consumer</module>
             <module>slow-consumer</module>
             <module>spring-integration</module>
+            <module>spring-boot-integration</module>
             <module>ssl-enabled</module>
             <module>ssl-enabled-crl-mqtt</module>
             <module>ssl-enabled-dual-authentication</module>

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/550c79b1/examples/features/standard/spring-boot-integration/README.md
----------------------------------------------------------------------
diff --git a/examples/features/standard/spring-boot-integration/README.md b/examples/features/standard/spring-boot-integration/README.md
new file mode 100644
index 0000000..075bbd0
--- /dev/null
+++ b/examples/features/standard/spring-boot-integration/README.md
@@ -0,0 +1,7 @@
+# ActiveMQ Artemis Spring Boot Example
+
+To run the example, simply type **mvn verify -Pexample** from this directory.
+
+This example shows how to setup and run an embedded broker within a Spring Boot Application
relying on [AMQP 1.0 JMS Spring Boot project](https://github.com/amqphub/amqp-10-jms-spring-boot)
for configuration.
+
+

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/550c79b1/examples/features/standard/spring-boot-integration/pom.xml
----------------------------------------------------------------------
diff --git a/examples/features/standard/spring-boot-integration/pom.xml b/examples/features/standard/spring-boot-integration/pom.xml
new file mode 100644
index 0000000..10d4d76
--- /dev/null
+++ b/examples/features/standard/spring-boot-integration/pom.xml
@@ -0,0 +1,102 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+  http://www.apache.org/licenses/LICENSE-2.0
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+	<parent>
+		<groupId>org.apache.activemq.examples.broker</groupId>
+		<artifactId>jms-examples</artifactId>
+		<version>2.7.0-SNAPSHOT</version>
+	</parent>
+	<artifactId>spring-boot-integration</artifactId>
+	<name>ActiveMQ Artemis JMS Spring Boot Integration Example</name>
+
+	<properties>
+		<activemq.basedir>${project.basedir}/../../../..</activemq.basedir>
+
+		<!-- AMQP Spring Starter -->
+		<amqp-10-jms-spring.version>2.0.1</amqp-10-jms-spring.version>
+	</properties>
+
+	<dependencies>
+		<dependency>
+			<groupId>org.apache.activemq</groupId>
+			<artifactId>artemis-amqp-protocol</artifactId>
+			<version>${project.version}</version>
+		</dependency>
+		<dependency>
+			<groupId>org.amqphub.spring</groupId>
+			<artifactId>amqp-10-jms-spring-boot-starter</artifactId>
+			<version>${amqp-10-jms-spring.version}</version>
+		</dependency>
+	</dependencies>
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>org.springframework.boot</groupId>
+				<artifactId>spring-boot-maven-plugin</artifactId>
+				<version>2.0.4.RELEASE</version>
+			</plugin>
+		</plugins>
+	</build>
+	<profiles>
+		<profile>
+			<id>example</id>
+			<build>
+				<plugins>
+					<plugin>
+						<groupId>org.apache.activemq</groupId>
+						<artifactId>artemis-maven-plugin</artifactId>
+						<executions>
+							<execution>
+								<id>runClient</id>
+								<goals>
+									<goal>runClient</goal>
+								</goals>
+								<configuration>
+									<clientClass>org.apache.activemq.artemis.jms.example.springboot.Application</clientClass>
+								</configuration>
+							</execution>
+						</executions>
+						<dependencies>
+							<dependency>
+								<groupId>org.apache.activemq.examples.broker</groupId>
+								<artifactId>spring-boot-integration</artifactId>
+								<version>${project.version}</version>
+							</dependency>
+						</dependencies>
+					</plugin>
+					<plugin>
+						<groupId>org.apache.maven.plugins</groupId>
+						<artifactId>maven-clean-plugin</artifactId>
+					</plugin>
+				</plugins>
+			</build>
+		</profile>
+		<profile>
+			<id>release</id>
+			<build>
+				<plugins>
+					<plugin>
+						<groupId>com.vladsch.flexmark</groupId>
+						<artifactId>markdown-page-generator-plugin</artifactId>
+					</plugin>
+				</plugins>
+			</build>
+		</profile>
+	</profiles>
+</project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/550c79b1/examples/features/standard/spring-boot-integration/src/main/java/org/apache/activemq/artemis/jms/example/springboot/Application.java
----------------------------------------------------------------------
diff --git a/examples/features/standard/spring-boot-integration/src/main/java/org/apache/activemq/artemis/jms/example/springboot/Application.java
b/examples/features/standard/spring-boot-integration/src/main/java/org/apache/activemq/artemis/jms/example/springboot/Application.java
new file mode 100644
index 0000000..a42c6ce
--- /dev/null
+++ b/examples/features/standard/spring-boot-integration/src/main/java/org/apache/activemq/artemis/jms/example/springboot/Application.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.artemis.jms.example.springboot;
+
+import org.apache.activemq.artemis.core.config.impl.SecurityConfiguration;
+import org.apache.activemq.artemis.core.server.embedded.EmbeddedActiveMQ;
+import org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager;
+import org.apache.activemq.artemis.spi.core.security.jaas.InVMLoginModule;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.context.annotation.Bean;
+import org.springframework.jms.annotation.EnableJms;
+
+/**
+ * @see <a href="https://spring.io/guides/gs/messaging-jms/">Spring JMS Messaging Guide</a>
+ */
+@SpringBootApplication
+@EnableJms
+public class Application {
+   public Application() {
+
+   }
+
+   public static void main(String[] args) throws InterruptedException {
+      final ConfigurableApplicationContext context = SpringApplication.run(Application.class);
+      System.out.println("********************* Sending message...");
+      MessageSender sender = context.getBean(MessageSender.class);
+      sender.send("Hello Artemis!");
+      Thread.sleep(1000);
+      context.close();
+   }
+
+   @Bean
+   public ActiveMQJAASSecurityManager securityManager(@Value("${amq.broker.user}") String
user,
+                                                      @Value("${amq.broker.password}") String
password,
+                                                      @Value("${amq.broker.role}") String
role) {
+      final SecurityConfiguration configuration = new SecurityConfiguration();
+      final ActiveMQJAASSecurityManager securityManager =
+               new ActiveMQJAASSecurityManager(InVMLoginModule.class.getName(), configuration);
+      configuration.addUser(user, password);
+      configuration.addRole(user, role);
+      configuration.setDefaultUser(user);
+
+      return securityManager;
+   }
+
+   @Bean(initMethod = "start", destroyMethod = "stop")
+   public EmbeddedActiveMQ embeddedActiveMQ(ActiveMQJAASSecurityManager securityManager)
{
+      final EmbeddedActiveMQ embeddedActiveMQ = new EmbeddedActiveMQ();
+      embeddedActiveMQ.setSecurityManager(securityManager);
+      return embeddedActiveMQ;
+   }
+
+}

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/550c79b1/examples/features/standard/spring-boot-integration/src/main/java/org/apache/activemq/artemis/jms/example/springboot/ExampleListener.java
----------------------------------------------------------------------
diff --git a/examples/features/standard/spring-boot-integration/src/main/java/org/apache/activemq/artemis/jms/example/springboot/ExampleListener.java
b/examples/features/standard/spring-boot-integration/src/main/java/org/apache/activemq/artemis/jms/example/springboot/ExampleListener.java
new file mode 100644
index 0000000..82bdc3e
--- /dev/null
+++ b/examples/features/standard/spring-boot-integration/src/main/java/org/apache/activemq/artemis/jms/example/springboot/ExampleListener.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.artemis.jms.example.springboot;
+
+import org.springframework.jms.annotation.JmsListener;
+import org.springframework.stereotype.Component;
+
+@Component
+public class ExampleListener {
+
+   @JmsListener(destination = "${amq.queue}")
+   public void receiveMessage(String message) {
+      System.out.println("*********************** MESSAGE RECEIVED: " + message);
+   }
+}

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/550c79b1/examples/features/standard/spring-boot-integration/src/main/java/org/apache/activemq/artemis/jms/example/springboot/MessageSender.java
----------------------------------------------------------------------
diff --git a/examples/features/standard/spring-boot-integration/src/main/java/org/apache/activemq/artemis/jms/example/springboot/MessageSender.java
b/examples/features/standard/spring-boot-integration/src/main/java/org/apache/activemq/artemis/jms/example/springboot/MessageSender.java
new file mode 100644
index 0000000..70f1124
--- /dev/null
+++ b/examples/features/standard/spring-boot-integration/src/main/java/org/apache/activemq/artemis/jms/example/springboot/MessageSender.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.artemis.jms.example.springboot;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.jms.core.JmsTemplate;
+import org.springframework.stereotype.Component;
+
+@Component
+public class MessageSender {
+
+   @Autowired
+   private JmsTemplate jmsTemplate;
+
+   @Value("${amq.queue}")
+   private String queue;
+
+   public MessageSender() {
+
+   }
+
+   public void send(String message) {
+      jmsTemplate.convertAndSend(queue, message);
+   }
+
+}

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/550c79b1/examples/features/standard/spring-boot-integration/src/main/resources/META-INF/additional-spring-configuration-metadata.json
----------------------------------------------------------------------
diff --git a/examples/features/standard/spring-boot-integration/src/main/resources/META-INF/additional-spring-configuration-metadata.json
b/examples/features/standard/spring-boot-integration/src/main/resources/META-INF/additional-spring-configuration-metadata.json
new file mode 100644
index 0000000..fbe5563
--- /dev/null
+++ b/examples/features/standard/spring-boot-integration/src/main/resources/META-INF/additional-spring-configuration-metadata.json
@@ -0,0 +1,44 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+{"properties": [
+  {
+    "name": "amq.queue",
+    "type": "java.lang.String",
+    "description": "A description for 'amq.queue'"
+  },
+  {
+    "name": "amq.broker.password",
+    "type": "java.lang.String",
+    "description": "A description for 'amq.broker.password'"
+  },
+  {
+    "name": "amq.broker.user",
+    "type": "java.lang.String",
+    "description": "A description for 'amq.broker.user'"
+  },
+  {
+    "name": "amq.broker.user",
+    "type": "java.lang.String",
+    "description": "A description for 'amq.broker.user'"
+  },
+  {
+    "name": "amq.broker.role",
+    "type": "java.lang.String",
+    "description": "A description for 'amq.broker.role'"
+  }
+]}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/550c79b1/examples/features/standard/spring-boot-integration/src/main/resources/application.properties
----------------------------------------------------------------------
diff --git a/examples/features/standard/spring-boot-integration/src/main/resources/application.properties
b/examples/features/standard/spring-boot-integration/src/main/resources/application.properties
new file mode 100644
index 0000000..14f0c2e
--- /dev/null
+++ b/examples/features/standard/spring-boot-integration/src/main/resources/application.properties
@@ -0,0 +1,23 @@
+## ---------------------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one or more
+## contributor license agreements.  See the NOTICE file distributed with
+## this work for additional information regarding copyright ownership.
+## The ASF licenses this file to You under the Apache License, Version 2.0
+## (the "License"); you may not use this file except in compliance with
+## the License.  You may obtain a copy of the License at
+##
+## http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+## ---------------------------------------------------------------------------
+amqphub.amqp10jms.remote-url=amqp://localhost:61616
+amqphub.amqp10jms.username=guest
+amqphub.amqp10jms.password=guest
+amq.broker.password=guest
+amq.broker.user=guest
+amq.broker.role=guest
+amq.queue=exampleQueue
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/550c79b1/examples/features/standard/spring-boot-integration/src/main/resources/broker.xml
----------------------------------------------------------------------
diff --git a/examples/features/standard/spring-boot-integration/src/main/resources/broker.xml
b/examples/features/standard/spring-boot-integration/src/main/resources/broker.xml
new file mode 100644
index 0000000..099363e
--- /dev/null
+++ b/examples/features/standard/spring-boot-integration/src/main/resources/broker.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<configuration xmlns="urn:activemq" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:activemq /schema/artemis-configuration.xsd">
+   <core xmlns="urn:activemq:core">
+
+      <persistence-enabled>false</persistence-enabled>
+
+      <acceptors>
+         <acceptor name="netty">tcp://0.0.0.0:61616?protocols=AMQP,CORE</acceptor>
+      </acceptors>
+
+      <security-settings>
+         <security-setting match="#">
+            <permission roles="guest" type="createAddress"/>
+            <permission roles="guest" type="deleteAddress"/>
+            <permission roles="guest" type="createDurableQueue"/>
+            <permission roles="guest" type="deleteDurableQueue"/>
+            <permission roles="guest" type="createNonDurableQueue"/>
+            <permission roles="guest" type="deleteNonDurableQueue"/>
+            <permission roles="guest" type="consume"/>
+            <permission roles="guest" type="send"/>
+         </security-setting>
+      </security-settings>
+   </core>
+</configuration>

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/550c79b1/examples/features/standard/spring-boot-integration/src/main/resources/logback.xml
----------------------------------------------------------------------
diff --git a/examples/features/standard/spring-boot-integration/src/main/resources/logback.xml
b/examples/features/standard/spring-boot-integration/src/main/resources/logback.xml
new file mode 100644
index 0000000..2f867cd
--- /dev/null
+++ b/examples/features/standard/spring-boot-integration/src/main/resources/logback.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<configuration debug="false">
+	<appender name="STDOUT"
+		class="ch.qos.logback.core.ConsoleAppender">
+		<layout class="ch.qos.logback.classic.PatternLayout">
+			<Pattern>
+				%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n
+			</Pattern>
+		</layout>
+	</appender>
+
+	<logger name="org.springframework" level="INFO">
+	</logger>
+
+
+	<root level="INFO">
+		<appender-ref ref="STDOUT" />
+	</root>
+
+</configuration>


Mime
View raw message