• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

group of test apps


Commit MetaInfo

修订版37713e431a7e71acba11fe8919543c4214ddbd59 (tree)
时间2014-01-29 12:33:22
作者astoria-d <astoria-d@mail...>
Commiterastoria-d

Log Message

jms test added

更改概述

差异

--- /dev/null
+++ b/jms-test1/build.xml
@@ -0,0 +1,59 @@
1+<project default="send" basedir=".">
2+
3+ <property name="proj_name" value="jms-test1" />
4+
5+ <!-- set global properties for this build -->
6+ <property environment="env"/>
7+ <property name="top" value="."/>
8+ <property name="src" value="src"/>
9+ <property name="build" value="build"/>
10+ <property name="jar_file" value="${jar_dir}/${proj_name}.jar"/>
11+ <property name="lib" value="lib"/>
12+
13+ <property name="deploy" value="${env.JBOSS_HOME}/standalone/deployments"/>
14+
15+ <property name="jms.jar" value="${env.JBOSS_HOME}\modules\javax\jms\api\main\jboss-jms-api_1.1_spec-1.0.0.Final.jar"/>
16+
17+ <property name="jboss.client.jar" value="${env.JBOSS_HOME}\bin\client\jboss-client-7.1.0.Final.jar"/>
18+
19+ <target name="clean">
20+ <!-- Delete our the ${build} and ${dist} directory trees -->
21+ <delete dir="${build}"/>
22+ </target>
23+
24+ <target name="init">
25+ <!-- Create the build directory structure used by compile and dist -->
26+ <mkdir dir="${build}"/>
27+ </target>
28+
29+ <target name="compile" depends="init">
30+ <!-- Compile the java code from ${src} into ${build} -->
31+ <javac
32+ debug="true"
33+ srcdir="${top}/${src}"
34+ destdir="${build}"
35+ classpath="${jms.jar}"/>
36+ </target>
37+
38+ <target name="send" depends="clean,compile">
39+ <java classname="motoSample.jms.JmsSender" fork="true">
40+ <classpath>
41+ <pathelement location="${build}"/>
42+ <pathelement location="${jboss.client.jar}"/>
43+ </classpath>
44+ </java>
45+ </target>
46+
47+ <target name="recv" depends="clean,compile">
48+ <java classname="motoSample.jms.JmsReceiver" fork="true">
49+ <classpath>
50+ <pathelement location="${build}"/>
51+ <pathelement location="${jboss.client.jar}"/>
52+ </classpath>
53+ </java>
54+ </target>
55+
56+
57+ <target name="all" depends="clean,compile" />
58+
59+</project>
--- /dev/null
+++ b/jms-test1/helloworld-jms/README.md
@@ -0,0 +1,257 @@
1+helloworld-jms: HelloWorld JMS Example
2+======================
3+Author: Weston Price
4+Level: Intermediate
5+Technologies: JMS
6+Summary: Demonstrates the use of a standalone (Java SE) JMS client
7+Target Product: EAP
8+Source: <https://github.com/jboss-jdf/jboss-as-quickstart/>
9+
10+What is it?
11+-----------
12+
13+This quickstart demonstrates the use of external JMS clients with JBoss Enterprise Application Platform 6 or JBoss AS 7.
14+
15+It contains the following:
16+
17+1. A message producer that sends messages to a JMS destination deployed to a JBoss Enterprise Application Platform 6 or JBoss AS 7 server.
18+
19+2. A message consumer that receives message from a JMS destination deployed to a JBoss Enterprise Application Platform 6 or JBoss AS 7 server.
20+
21+
22+System requirements
23+-------------------
24+
25+All you need to build this project is Java 6.0 (Java SDK 1.6) or better, Maven 3.0 or better.
26+
27+The application this project produces is designed to be run on JBoss Enterprise Application Platform 6 or JBoss AS 7.
28+
29+
30+Configure Maven
31+---------------
32+
33+If you have not yet done so, you must [Configure Maven](../README.md#configure-maven) before testing the quickstarts.
34+
35+
36+Add an Application User
37+----------------
38+This quickstart uses secured management interfaces and requires that you create an application user to access the running application. Instructions to set up the quickstart application user can be found here: [Add an Application User](../README.md#add-an-application-user)
39+
40+
41+Configure the JBoss Enterprise Application Platform 6 server
42+---------------------------
43+
44+If you are using the JBoss AS 7 Quickstart distribution, the server configuration file already contains the JMS `test` queue and you can skip this step.
45+
46+However, if you are using the JBoss Enterprise Application Platform 6 distribution, you need to add the JMS `test` queue to the application server configuration file. You can configure JMS by running the `configure-jms.cli` script provided in the root directory of this quickstart, by using the JBoss CLI interactively, or by manually editing the configuration file.
47+
48+_NOTE - Before you begin:_
49+
50+1. If it is running, stop the JBoss Enterprise Application Platform 6 or JBoss AS 7 Server.
51+2. Backup the file: `JBOSS_HOME/standalone/configuration/standalone-full.xml`
52+3. After you have completed testing this quickstart, you can replace this file to restore the server to its original configuration.
53+
54+#### Configure JMS by Running the JBoss CLI Script
55+
56+1. Start the JBoss Enterprise Application Platform 6 or JBoss AS 7 Server by typing the following:
57+
58+ For Linux: JBOSS_HOME_SERVER_1/bin/standalone.sh -c standalone-full.xml
59+ For Windows: JBOSS_HOME_SERVER_1\bin\standalone.bat -c standalone-full.xml
60+2. Open a new command line, navigate to the root directory of this quickstart, and run the following command, replacing JBOSS_HOME with the path to your server:
61+
62+ JBOSS_HOME/bin/jboss-cli.sh --connect --file=configure-jms.cli
63+This script adds the `test` queue to the `messaging` subsystem in the server configuration. You should see the following result when you run the script:
64+
65+ #1 jms-queue add --queue-address=testQueue --entries=queue/test,java:jboss/exported/jms/queue/test
66+ The batch executed successfully.
67+ {"outcome" => "success"}
68+
69+
70+#### Configure JMS Using the JBoss CLI Tool Interactively
71+
72+1. Start the JBoss Enterprise Application Platform 6 or JBoss AS 7 Server by typing the following:
73+
74+ For Linux: JBOSS_HOME_SERVER_1/bin/standalone.sh -c standalone-full.xml
75+ For Windows: JBOSS_HOME_SERVER_1\bin\standalone.bat -c standalone-full.xml
76+2. To start the JBoss CLI tool, open a new command line, navigate to the JBOSS_HOME directory, and type the following:
77+
78+ For Linux: bin/jboss-cli.sh --connect
79+ For Windows: bin\jboss-cli.bat --connect
80+3. At the prompt, type the following:
81+
82+ [standalone@localhost:9999 /] jms-queue add --queue-address=testQueue --entries=queue/test,java:jboss/exported/jms/queue/test
83+
84+#### Configure JMS by Manually Editing the Server Configuration File
85+
86+1. If it is running, stop the JBoss Enterprise Application Platform 6 or JBoss AS 7 Server.
87+2. Backup the file: `JBOSS_HOME/standalone/configuration/standalone-full.xml`
88+3. Open the file: JBOSS_HOME/standalone/configuration/standalone-full.xml
89+4. Add the JMS `test` queue as follows:
90+ * Find the messaging subsystem:
91+
92+ <subsystem xmlns="urn:jboss:domain:messaging:1.1">
93+ * Scroll to the end of this section and add the following XML after the `</jms-connection-factories>` end tag but before the `</hornetq-server>` element:
94+
95+ <jms-destinations>
96+ <jms-queue name="testQueue">
97+ <entry name="queue/test"/>
98+ <entry name="java:jboss/exported/jms/queue/test"/>
99+ </jms-queue>
100+ </jms-destinations>
101+ * Save the changes and close the file.
102+
103+
104+Start JBoss Enterprise Application Platform 6 or JBoss AS 7 with the Full Profile
105+---------------
106+
107+1. Open a command line and navigate to the root of the JBoss server directory.
108+2. The following shows the command line to start the server with the full profile:
109+
110+ For Linux: JBOSS_HOME/bin/standalone.sh -c standalone-full.xml
111+ For Windows: JBOSS_HOME\bin\standalone.bat -c standalone-full.xml
112+
113+
114+Build and Deploy the Quickstart
115+-------------------------
116+
117+To run the quickstart from the command line:
118+
119+1. Make sure you have started the JBoss server. See the instructions in the previous section.
120+
121+2. Open a command line and navigate to the root of the helloworld-jms quickstart directory:
122+
123+ cd PATH_TO_QUICKSTARTS/helloworld-jms
124+
125+3. Type the following command to compile and execute the quickstart:
126+
127+ For JBoss Enterprise Application Platform 6 (Maven user settings NOT configured):
128+
129+ mvn clean compile exec:java -s PATH_TO_QUICKSTARTS/example-settings.xml
130+
131+ For JBoss AS 7 or JBoss Enterprise Application Platform 6 (Maven user settings configured):
132+
133+ mvn clean compile exec:java
134+
135+
136+Investigate the Console Output
137+-------------------------
138+
139+If the maven command is successful, with the default configuration you will see output similar to this:
140+
141+ Mar 14, 2012 1:38:58 PM org.jboss.as.quickstarts.jms.HelloWorldJMSClient main
142+ INFO: Attempting to acquire connection factory "jms/RemoteConnectionFactory"
143+ Mar 14, 2012 1:38:58 PM org.jboss.as.quickstarts.jms.HelloWorldJMSClient main
144+ INFO: Found connection factory "jms/RemoteConnectionFactory" in JNDI
145+ Mar 14, 2012 1:38:58 PM org.jboss.as.quickstarts.jms.HelloWorldJMSClient main
146+ INFO: Attempting to acquire destination "jms/queue/test"
147+ Mar 14, 2012 1:38:58 PM org.jboss.as.quickstarts.jms.HelloWorldJMSClient main
148+ INFO: Found destination "jms/queue/test" in JNDI
149+ Mar 14, 2012 1:38:58 PM org.jboss.as.quickstarts.jms.HelloWorldJMSClient main
150+ INFO: Sending 1 messages with content: Hello, World!
151+ Mar 14, 2012 1:38:58 PM org.jboss.as.quickstarts.jms.HelloWorldJMSClient main
152+ INFO: Received message with content Hello, World!
153+
154+_Note_: After the above INFO message, you may see the following error. You can ignore the error as it is a well known error message and does not indicate the maven command was unsuccessful in any way.
155+
156+ Mar 14, 2012 1:38:58 PM org.jboss.naming.remote.protocol.v1.RemoteNamingStoreV1$MessageReceiver handleEnd
157+ ERROR: Channel end notification received, closing channel Channel ID cd114175 (outbound) of Remoting connection 00392fe8 to localhost/127.0.0.1:4447
158+
159+
160+Optional Properties
161+-------------------
162+
163+The example provides for a certain amount of customization for the `mvn:exec` plugin using the system properties.
164+
165+* `username`
166+
167+ This username is used for both the JMS connection and the JNDI look-up. Instructions to set up the quickstart application user can be found here: [Add an Application User](../README.md#add-an-application-user).
168+
169+ Default: `quickstartUser`
170+
171+* `password`
172+
173+ This password is used for both the JMS connection and the JNDI look-up. Instructions to set up the quickstart application user can be found here: [Add an Application User](../README.md#add-an-application-user)
174+
175+ Default: `quickstartPwd1!`
176+
177+* `connection.factory`
178+
179+ The name of the JMS ConnectionFactory you want to use.
180+
181+ Default: `jms/RemoteConnectionFactory`
182+
183+* `destination`
184+
185+ The name of the JMS Destination you want to use.
186+
187+ Default: `jms/queue/test`
188+
189+* `message.count`
190+
191+ The number of JMS messages you want to produce and consume.
192+
193+ Default: `1`
194+
195+* `message.content`
196+
197+ The content of the JMS TextMessage.
198+
199+ Default: `"Hello, World!"`
200+
201+* `java.naming.provider.url`
202+
203+ This property allows configuration of the JNDI directory used to lookup the JMS destination. This is useful when the client resides on another host.
204+
205+ Default: `"localhost"`
206+
207+
208+Undeploy the Archive
209+--------------------
210+
211+1. Make sure you have started the JBoss Server as described above.
212+2. Open a command line and navigate to the root directory of this quickstart.
213+3. When you are finished testing, type this command to undeploy the archive:
214+
215+ mvn jboss-as:undeploy
216+
217+
218+Remove the JMS Configuration
219+----------------------------
220+
221+You can remove the JMS configuration by running the `remove-jms.cli` script provided in the root directory of this quickstart or by manually restoring the back-up copy the configuration file.
222+
223+### Remove the JMS Configuration by Running the JBoss CLI Script
224+
225+1. Start the JBoss Enterprise Application Platform 6 or JBoss AS 7 Server by typing the following:
226+
227+ For Linux: JBOSS_HOME_SERVER_1/bin/standalone.sh -c standalone-full.xml
228+ For Windows: JBOSS_HOME_SERVER_1\bin\standalone.bat -c standalone-full.xml
229+2. Open a new command line, navigate to the root directory of this quickstart, and run the following command, replacing JBOSS_HOME with the path to your server:
230+
231+ JBOSS_HOME/bin/jboss-cli.sh --connect --file=remove-jms.cli
232+This script removes the `test` queue from the `messaging` subsystem in the server configuration. You should see the following result when you run the script:
233+
234+ #1 jms-queue remove --queue-address=testQueue
235+ The batch executed successfully.
236+ {"outcome" => "success"}
237+
238+
239+### Remove the JMS Configuration Manually
240+1. If it is running, stop the JBoss Enterprise Application Platform 6 or JBoss AS 7 Server.
241+2. Replace the `JBOSS_HOME/standalone/configuration/standalone-full.xml` file with the back-up copy of the file.
242+
243+
244+Run the Quickstart in JBoss Developer Studio or Eclipse
245+-------------------------------------
246+You can also start the server and deploy the quickstarts from Eclipse using JBoss tools. For more information, see [Use JBoss Developer Studio or Eclipse to Run the Quickstarts](../README.md#use-jboss-developer-studio-or-eclipse-to-run-the-quickstarts)
247+
248+
249+Debug the Application
250+------------------------------------
251+
252+If you want to debug the source code or look at the Javadocs of any library in the project, run either of the following commands to pull them into your local repository. The IDE should then detect them.
253+
254+ mvn dependency:sources
255+ mvn dependency:resolve -Dclassifier=javadoc
256+
257+
--- /dev/null
+++ b/jms-test1/helloworld-jms/configure-jms.cli
@@ -0,0 +1,15 @@
1+# Batch script to add the JMS configuration to the JBoss server
2+
3+# Start batching commands
4+batch
5+
6+# Configure the JMS test queue
7+jms-queue add --queue-address=testQueue --entries=queue/test,java:jboss/exported/jms/queue/test
8+
9+# Run the batch commands
10+run-batch
11+
12+# Reload the server configuration
13+:reload
14+
15+
--- /dev/null
+++ b/jms-test1/helloworld-jms/helloworld-jms-logging.properties
@@ -0,0 +1,39 @@
1+#
2+# JBoss, Home of Professional Open Source
3+# Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual
4+# contributors by the @authors tag. See the copyright.txt in the
5+# distribution for a full listing of individual contributors.
6+#
7+# Licensed under the Apache License, Version 2.0 (the "License");
8+# you may not use this file except in compliance with the License.
9+# You may obtain a copy of the License at
10+# http://www.apache.org/licenses/LICENSE-2.0
11+# Unless required by applicable law or agreed to in writing, software
12+# distributed under the License is distributed on an "AS IS" BASIS,
13+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+# See the License for the specific language governing permissions and
15+# limitations under the License.
16+#
17+
18+# Specify the handlers to create in the root logger
19+# (all loggers are children of the root logger)
20+# The following creates two handlers
21+handlers = java.util.logging.ConsoleHandler, java.util.logging.FileHandler
22+
23+# Set the default logging level for the root logger
24+.level = ALL
25+
26+# Set the default logging level for new ConsoleHandler instances
27+java.util.logging.ConsoleHandler.level = ALL
28+
29+# Set the default logging level for new FileHandler instances
30+java.util.logging.FileHandler.level = ALL
31+java.util.logging.FileHandler.pattern = helloworld-jms.log
32+java.util.logging.FileHandler.limit = 50000
33+java.util.logging.FileHandler.count = 1
34+
35+# Set the default formatter for new ConsoleHandler instances
36+java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
37+
38+# Set the default logging level for the logger named com.mycompany
39+org.jboss.as.quickstarts.jms = ALL
--- /dev/null
+++ b/jms-test1/helloworld-jms/pom.xml
@@ -0,0 +1,142 @@
1+<?xml version="1.0"?>
2+<!--
3+ JBoss, Home of Professional Open Source
4+ Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual
5+ contributors by the @authors tag. See the copyright.txt in the
6+ distribution for a full listing of individual contributors.
7+
8+ Licensed under the Apache License, Version 2.0 (the "License");
9+ you may not use this file except in compliance with the License.
10+ You may obtain a copy of the License at
11+ http://www.apache.org/licenses/LICENSE-2.0
12+ Unless required by applicable law or agreed to in writing, software
13+ distributed under the License is distributed on an "AS IS" BASIS,
14+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+ See the License for the specific language governing permissions and
16+ limitations under the License.
17+-->
18+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
20+ <modelVersion>4.0.0</modelVersion>
21+
22+ <groupId>org.jboss.as.quickstarts</groupId>
23+ <artifactId>jboss-as-helloworld-jms</artifactId>
24+ <version>7.1.2-SNAPSHOT</version>
25+ <packaging>jar</packaging>
26+ <name>JBoss EAP Quickstart: helloworld-jms</name>
27+ <description>helloworld-jms: Helloworld JMS external producer/consumer client</description>
28+
29+ <url>http://jboss.org/jbossas</url>
30+ <licenses>
31+ <license>
32+ <name>Apache License, Version 2.0</name>
33+ <distribution>repo</distribution>
34+ <url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
35+ </license>
36+ </licenses>
37+
38+ <properties>
39+ <!-- Explicitly declaring the source encoding eliminates the following message: -->
40+ <!-- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered
41+ resources, i.e. build is platform dependent! -->
42+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
43+
44+ <!-- JBoss dependency versions -->
45+
46+ <version.jboss.maven.plugin>7.4.Final</version.jboss.maven.plugin>
47+
48+ <!-- moto changed.
49+ version.jboss.as>7.2.0.Final</version.jboss.as -->
50+ <version.jboss.as>7.1.0.Final</version.jboss.as>
51+
52+
53+ <!-- Alternatively, comment out the above line, and un-comment the
54+ line below to use version 7.2.0.Final-redhat-8 which is a release certified
55+ to work with JBoss EAP 6. It requires you have access to the JBoss EAP 6
56+ maven repository. -->
57+ <!-- <version.jboss.as>7.2.0.Final-redhat-8</version.jboss.as> -->
58+
59+ <!-- other plugin versions -->
60+ <version.jar.plugin>2.2</version.jar.plugin>
61+ <version.exec.plugin>1.2.1</version.exec.plugin>
62+
63+ <!-- maven-compiler-plugin -->
64+ <maven.compiler.target>1.6</maven.compiler.target>
65+ <maven.compiler.source>1.6</maven.compiler.source>
66+ </properties>
67+
68+ <dependencies>
69+ <dependency>
70+ <groupId>org.jboss.as</groupId>
71+ <artifactId>jboss-as-jms-client-bom</artifactId>
72+ <version>${version.jboss.as}</version>
73+ <type>pom</type>
74+ </dependency>
75+ </dependencies>
76+
77+ <build>
78+ <finalName>${project.artifactId}</finalName>
79+ <plugins>
80+ <plugin>
81+ <groupId>org.codehaus.mojo</groupId>
82+ <artifactId>exec-maven-plugin</artifactId>
83+ <version>${version.exec.plugin}</version>
84+ <configuration>
85+ <mainClass>org.jboss.as.quickstarts.jms.HelloWorldJMSClient</mainClass>
86+ <systemProperties>
87+ <!-- Override the default values of properties passed to the HelloWorldJMSClient -->
88+ <!--
89+ <systemProperty>
90+ <key>java.naming.provider.url</key>
91+ <value>remote://localhost:4447</value>
92+ </systemProperty>
93+ <systemProperty>
94+ <key>username</key>
95+ <value>quickstartUser</value>
96+ </systemProperty>
97+ <systemProperty>
98+ <key>password</key>
99+ <value>quickstartPwd1!</value>
100+ </systemProperty>
101+ <systemProperty>
102+ <key>connection.factory</key>
103+ <value>jms/RemoteConnectionFactory</value>
104+ </systemProperty>
105+ <systemProperty>
106+ <key>destination</key>
107+ <value>jms/queue/test</value>
108+ </systemProperty>
109+ <systemProperty>
110+ <key>message.count</key>
111+ <value>1</value>
112+ </systemProperty>
113+ <systemProperty>
114+ <key>message.content</key>
115+ <value>Hello, World!</value>
116+ </systemProperty-->
117+ <systemProperty>
118+ <key>java.logging.config.file</key>
119+ <value>./helloworld-jms-logging.properties</value>
120+ </systemProperty>
121+ </systemProperties>
122+ </configuration>
123+ </plugin>
124+ <plugin>
125+ <artifactId>maven-jar-plugin</artifactId>
126+ <version>${version.jar.plugin}</version>
127+ <configuration>
128+ </configuration>
129+ </plugin>
130+ <!-- JBoss AS plugin to deploy war -->
131+ <plugin>
132+ <groupId>org.jboss.as.plugins</groupId>
133+ <artifactId>jboss-as-maven-plugin</artifactId>
134+ <version>${version.jboss.maven.plugin}</version>
135+ <configuration>
136+ <username>admin</username>
137+ <password>admin</password>
138+ </configuration>
139+ </plugin>
140+ </plugins>
141+ </build>
142+</project>
--- /dev/null
+++ b/jms-test1/helloworld-jms/remove-jms.cli
@@ -0,0 +1,15 @@
1+# Batch script to remove the the JMS configuration from the JBoss server
2+
3+# Start batching commands
4+batch
5+
6+# Configure the JMS test queue
7+jms-queue remove --queue-address=testQueue
8+
9+# Run the batch commands
10+run-batch
11+
12+# Reload the server configuration
13+:reload
14+
15+
--- /dev/null
+++ b/jms-test1/helloworld-jms/src/main/java/org/jboss/as/quickstarts/jms/HelloWorldJMSClient.java
@@ -0,0 +1,120 @@
1+/*
2+ * JBoss, Home of Professional Open Source
3+ * Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual
4+ * contributors by the @authors tag. See the copyright.txt in the
5+ * distribution for a full listing of individual contributors.
6+ *
7+ * Licensed under the Apache License, Version 2.0 (the "License");
8+ * you may not use this file except in compliance with the License.
9+ * You may obtain a copy of the License at
10+ * http://www.apache.org/licenses/LICENSE-2.0
11+ * Unless required by applicable law or agreed to in writing, software
12+ * distributed under the License is distributed on an "AS IS" BASIS,
13+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+ * See the License for the specific language governing permissions and
15+ * limitations under the License.
16+ */
17+package org.jboss.as.quickstarts.jms;
18+
19+import java.util.logging.Logger;
20+import java.util.Properties;
21+
22+import javax.jms.Connection;
23+import javax.jms.ConnectionFactory;
24+import javax.jms.Destination;
25+import javax.jms.MessageConsumer;
26+import javax.jms.MessageProducer;
27+import javax.jms.Session;
28+import javax.jms.TextMessage;
29+import javax.naming.Context;
30+import javax.naming.InitialContext;
31+
32+public class HelloWorldJMSClient {
33+ private static final Logger log = Logger.getLogger(HelloWorldJMSClient.class.getName());
34+
35+ // Set up all the default values
36+ private static final String DEFAULT_MESSAGE = "Hello, World!";
37+ private static final String DEFAULT_CONNECTION_FACTORY = "jms/RemoteConnectionFactory";
38+ private static final String DEFAULT_DESTINATION = "jms/queue/test";
39+ private static final String DEFAULT_MESSAGE_COUNT = "1";
40+/* motooka changed
41+ private static final String DEFAULT_USERNAME = "quickstartUser";
42+ private static final String DEFAULT_PASSWORD = "quickstartPwd1!";
43+ */
44+
45+ //ref: http://www.mastertheboss.com/jboss-as-7/jboss-as-7-remote-ejb-client-tutorial
46+ private static final String DEFAULT_USERNAME = "jmsuser";
47+ private static final String DEFAULT_PASSWORD = "jmspassword";
48+ private static final String INITIAL_CONTEXT_FACTORY = "org.jboss.naming.remote.client.InitialContextFactory";
49+ private static final String PROVIDER_URL = "remote://localhost:4447";
50+
51+ public static void main(String[] args) throws Exception {
52+
53+ ConnectionFactory connectionFactory = null;
54+ Connection connection = null;
55+ Session session = null;
56+ MessageProducer producer = null;
57+ MessageConsumer consumer = null;
58+ Destination destination = null;
59+ TextMessage message = null;
60+ Context context = null;
61+
62+ try {
63+ // Set up the context for the JNDI lookup
64+ final Properties env = new Properties();
65+ env.put(Context.INITIAL_CONTEXT_FACTORY, INITIAL_CONTEXT_FACTORY);
66+ env.put(Context.PROVIDER_URL, System.getProperty(Context.PROVIDER_URL, PROVIDER_URL));
67+ env.put(Context.SECURITY_PRINCIPAL, System.getProperty("username", DEFAULT_USERNAME));
68+ env.put(Context.SECURITY_CREDENTIALS, System.getProperty("password", DEFAULT_PASSWORD));
69+ context = new InitialContext(env);
70+
71+ // Perform the JNDI lookups
72+ String connectionFactoryString = System.getProperty("connection.factory", DEFAULT_CONNECTION_FACTORY);
73+ log.info("Attempting to acquire connection factory \"" + connectionFactoryString + "\"");
74+ connectionFactory = (ConnectionFactory) context.lookup(connectionFactoryString);
75+ log.info("Found connection factory \"" + connectionFactoryString + "\" in JNDI");
76+
77+ String destinationString = System.getProperty("destination", DEFAULT_DESTINATION);
78+ log.info("Attempting to acquire destination \"" + destinationString + "\"");
79+ destination = (Destination) context.lookup(destinationString);
80+ log.info("Found destination \"" + destinationString + "\" in JNDI");
81+
82+ // Create the JMS connection, session, producer, and consumer
83+ connection = connectionFactory.createConnection(System.getProperty("username", DEFAULT_USERNAME), System.getProperty("password", DEFAULT_PASSWORD));
84+ session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
85+ producer = session.createProducer(destination);
86+ consumer = session.createConsumer(destination);
87+ connection.start();
88+
89+ int count = Integer.parseInt(System.getProperty("message.count", DEFAULT_MESSAGE_COUNT));
90+ String content = System.getProperty("message.content", DEFAULT_MESSAGE);
91+
92+ log.info("Sending " + count + " messages with content: " + content);
93+
94+ // Send the specified number of messages
95+ for (int i = 0; i < count; i++) {
96+ message = session.createTextMessage(content);
97+ producer.send(message);
98+ }
99+
100+ // Then receive the same number of messages that were sent
101+ for (int i = 0; i < count; i++) {
102+ message = (TextMessage) consumer.receive(5000);
103+ log.info("Received message with content " + message.getText());
104+ }
105+ } catch (Exception e) {
106+ log.severe(e.getMessage());
107+ throw e;
108+ } finally {
109+ if (context != null) {
110+ context.close();
111+ }
112+
113+ // closing the connection takes care of the session, producer, and consumer
114+ if (connection != null) {
115+ connection.close();
116+ }
117+ }
118+ }
119+}
120+
--- /dev/null
+++ b/jms-test1/memo.txt
@@ -0,0 +1,58 @@
1+
2+-------------jms setting -------------
3+1. jms queue add
4+
5+# jms-queue add --queue-address=testQueue --entries=queue/test,java:jboss/exported/jms/queue/test
6+
7+2. check
8+# cd /subsystem=messaging/hornetq-server=default/jms-queue=testQueue
9+# :read-resource
10+{
11+ "outcome" => "success",
12+ "result" => {
13+ "durable" => true,
14+ "entries" => [
15+ "queue/test",
16+ "java:jboss/exported/jms/queue/test"
17+ ],
18+ "selector" => undefined
19+ }
20+}
21+
22+
23+3. remove queue
24+# jms-queue remove --queue-address=testQueue
25+
26+
27+---------------- quick start example code modification-----------
28+
29+ <!-- moto changed.
30+ version.jboss.as>7.2.0.Final</version.jboss.as -->
31+ <version.jboss.as>7.1.0.Final</version.jboss.as>
32+
33+---------------jboss application user management.---------------
34+
35+usr-add.bat :
36+
37+What type of user do you wish to add?
38+ a) Management User (mgmt-users.properties)
39+ b) Application User (application-users.properties)
40+(a): b
41+
42+Enter the details of the new user to add.
43+Realm (ApplicationRealm) :
44+Username : jmsuser
45+Password :
46+Re-enter Password :
47+What roles do you want this user to belong to? (Please enter a comma separated l
48+ist, or leave blank for none) :guest
49+ ^^^^^^^
50+
51+
52+
53+
54+*** to remove the application user, remove the line that has the user name you added from the following files.
55+C:\Users\dmotooka\AppData\jboss-as-7.1.0.Final\standalone\configuration\application-roles.properties
56+C:\Users\dmotooka\AppData\jboss-as-7.1.0.Final\standalone\configuration\application-users.properties
57+C:\Users\dmotooka\AppData\jboss-as-7.1.0.Final\domain\configuration\application-roles.properties
58+C:\Users\dmotooka\AppData\jboss-as-7.1.0.Final\domain\configuration\application-users.properties
--- /dev/null
+++ b/jms-test1/src/motoSample/jms/JmsReceiver.java
@@ -0,0 +1,95 @@
1+package motoSample.jms;
2+
3+import java.util.Properties;
4+
5+import javax.jms.QueueConnectionFactory;
6+import javax.jms.QueueConnection;
7+import javax.jms.Queue;
8+import javax.jms.Session;
9+import javax.jms.QueueSession;
10+import javax.jms.QueueReceiver;
11+import javax.jms.TextMessage;
12+import javax.jms.Message;
13+import javax.jms.ObjectMessage;
14+import javax.jms.JMSException;
15+
16+import javax.naming.Context;
17+import javax.naming.InitialContext;
18+import javax.naming.NamingException;
19+
20+
21+public class JmsReceiver
22+{
23+ private static final String JMS_FACTORY = "jms/RemoteConnectionFactory";
24+ private static final String QUEUE_NAME = "jms/queue/test";
25+
26+ private static final String INITIAL_CONTEXT_FACTORY = "org.jboss.naming.remote.client.InitialContextFactory";
27+ private static final String PROVIDER_URL = "remote://localhost:4447";
28+ private static final String DEFAULT_USERNAME = "jmsuser";
29+ private static final String DEFAULT_PASSWORD = "jmspassword";
30+
31+ public static void main(String[] args) throws Exception {
32+
33+ // コンテキスト作成
34+ Context ctx = initContext();
35+
36+ // コネクションファクトリーとキューを取得
37+ QueueConnectionFactory factory;
38+ Queue queue;
39+ try {
40+ factory = (QueueConnectionFactory) ctx.lookup(JMS_FACTORY);
41+ queue = (Queue) ctx.lookup(QUEUE_NAME);
42+ } finally {
43+ ctx.close();
44+ }
45+
46+ QueueConnection connection = null;
47+ QueueSession session = null;
48+ QueueReceiver receiver = null;
49+ try {
50+ // コネクションを作成
51+ connection = factory.createQueueConnection(System.getProperty("username", DEFAULT_USERNAME), System.getProperty("password", DEFAULT_PASSWORD));
52+
53+ // セッションを作成
54+ session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
55+
56+ // キューレシーバーを作成
57+ receiver = session.createReceiver(queue);
58+
59+ // メッセージ受信開始
60+ connection.start();
61+
62+ int cnt;
63+ for (cnt = 0; cnt < 5; cnt++) {
64+ Message msg = receiver.receive();
65+ if (msg instanceof TextMessage) {
66+ TextMessage tm = (TextMessage) msg;
67+ System.out.println("受信:" + tm.getText());
68+ } else if (msg instanceof ObjectMessage) {
69+ ObjectMessage om = (ObjectMessage) msg;
70+ Object obj = om.getObject();
71+ System.out.println("受信:" + obj);
72+ }
73+ }
74+
75+ } catch (Exception e) {
76+ System.out.println(e.getMessage());
77+ throw e;
78+ } finally {
79+ if (connection != null) {
80+ try { connection.close(); } catch (JMSException e) {}
81+ }
82+ }
83+ }
84+
85+ public static Context initContext() throws NamingException {
86+ final Properties env = new Properties();
87+ env.put(Context.INITIAL_CONTEXT_FACTORY, INITIAL_CONTEXT_FACTORY);
88+ env.put(Context.PROVIDER_URL, System.getProperty(Context.PROVIDER_URL, PROVIDER_URL));
89+ env.put(Context.SECURITY_PRINCIPAL, System.getProperty("username", DEFAULT_USERNAME));
90+ env.put(Context.SECURITY_CREDENTIALS, System.getProperty("password", DEFAULT_PASSWORD));
91+ Context context = new InitialContext(env);
92+
93+ return context;
94+ }
95+}
--- /dev/null
+++ b/jms-test1/src/motoSample/jms/JmsSender.java
@@ -0,0 +1,86 @@
1+package motoSample.jms;
2+
3+import java.util.Properties;
4+
5+import javax.jms.QueueConnectionFactory;
6+import javax.jms.QueueConnection;
7+import javax.jms.Queue;
8+import javax.jms.Session;
9+import javax.jms.QueueSession;
10+import javax.jms.QueueSender;
11+import javax.jms.TextMessage;
12+import javax.jms.JMSException;
13+
14+import javax.naming.Context;
15+import javax.naming.InitialContext;
16+import javax.naming.NamingException;
17+
18+
19+public class JmsSender
20+{
21+ private static final String JMS_FACTORY = "jms/RemoteConnectionFactory";
22+ private static final String QUEUE_NAME = "jms/queue/test";
23+
24+ private static final String INITIAL_CONTEXT_FACTORY = "org.jboss.naming.remote.client.InitialContextFactory";
25+ private static final String PROVIDER_URL = "remote://localhost:4447";
26+ private static final String DEFAULT_USERNAME = "jmsuser";
27+ private static final String DEFAULT_PASSWORD = "jmspassword";
28+
29+ public static void main(String args[]) throws Exception {
30+
31+ // コンテキスト作成
32+ Context ctx = initContext(); //APサーバー毎に異なる
33+
34+ // コネクションファクトリーとキューを取得
35+ QueueConnectionFactory factory;
36+ Queue queue;
37+ try {
38+ factory = (QueueConnectionFactory) ctx.lookup(JMS_FACTORY);
39+ queue = (Queue) ctx.lookup(QUEUE_NAME);
40+ } finally {
41+ ctx.close();
42+ }
43+
44+ QueueConnection connection = null;
45+ QueueSession session = null;
46+ QueueSender sender = null;
47+ try {
48+ // コネクションを作成
49+ connection = factory.createQueueConnection(System.getProperty("username", DEFAULT_USERNAME), System.getProperty("password", DEFAULT_PASSWORD));
50+
51+ // セッションを作成
52+ session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
53+
54+ // キューセンダーを作成
55+ sender = session.createSender(queue);
56+
57+ // メッセージ作成
58+ TextMessage msg = session.createTextMessage();
59+ msg.setText("テキストメッセージ!");
60+
61+ // メッセージ送信
62+ connection.start(); //これは無くても動くような…
63+ sender.send(msg);
64+ System.out.println("送信:" + msg);
65+
66+ } catch (Exception e) {
67+ System.out.println(e.getMessage());
68+ throw e;
69+ } finally {
70+ if (connection != null) {
71+ try { connection.close(); } catch (JMSException e) {}
72+ }
73+ }
74+ }
75+
76+ public static Context initContext() throws NamingException {
77+ final Properties env = new Properties();
78+ env.put(Context.INITIAL_CONTEXT_FACTORY, INITIAL_CONTEXT_FACTORY);
79+ env.put(Context.PROVIDER_URL, System.getProperty(Context.PROVIDER_URL, PROVIDER_URL));
80+ env.put(Context.SECURITY_PRINCIPAL, System.getProperty("username", DEFAULT_USERNAME));
81+ env.put(Context.SECURITY_CREDENTIALS, System.getProperty("password", DEFAULT_PASSWORD));
82+ Context context = new InitialContext(env);
83+
84+ return context;
85+ }
86+}