-
-
Save IngmarBoddington/fb4824f5417fc79cbebc to your computer and use it in GitHub Desktop.
JMS Specific Java Notes (Glassfish, ActiveMQ)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Message Types (http://docs.oracle.com/javaee/6/api/javax/jms/Message.html) | |
- String - Commonly used to avoid versioning issues | |
- Object (serialised) | |
- ByteMessage | |
- MapMessage | |
- StreamMessage | |
JNDI | |
- Java Naming Directory Index | |
- Dependancy Injections | |
- Beans, Queues, Connection Factory | |
Queue Implementations | |
- e.g. Jboss, activemq, rabbitmq... | |
- Implement JMS API | |
Queues + Topics | |
- Queue consumed by one | |
- Topic consumed by all | |
- Problems if consumer is off | |
Connection factory | |
- Object a client uses to create a connection with a provider. | |
Setup using Glassfish Queue (JMS) | |
export JAVA_HOME=$(/usr/libexec/java_home); | |
export J2EE_HOME=/Users/iboddington/glassfish4/glassfish; | |
export CLASSPATH=.:/Users/iboddington/glassfish4/mq/lib/*:/Users/iboddington/glassfish4/glassfish/modules/*; | |
export DISPLAY=:0; | |
Needed CLASSPATH as above to get below to compile (example Sender / Receiver from tutorial): | |
javac SimpleQueueSender.java | |
javac SimpleQueueReceiver.java | |
java -Djms.properties=$J2EE_HOME/config/jms_client.properties SimpleQueueSender jms/testQueue 3 | |
java -Djms.properties=$J2EE_HOME/config/jms_client.properties SimpleQueueReceiver jms/testQueue | |
Glassfish Install | |
1. Download / Install Java EE / glassfish: http://www.oracle.com/technetwork/java/javaee/downloads/index.html | |
2. Setup env vars | |
export JAVA_HOME=$(/usr/libexec/java_home); | |
export J2EE_HOME=/Users/iboddington/glassfish4/glassfish; | |
export CLASSPATH=.:/Users/iboddington/glassfish4/mq/lib/*:/Users/iboddington/glassfish4/glassfish/modules/*; | |
export DISPLAY=:0; | |
alias glassfish='/Users/iboddington/glassfish4/glassfish/bin/startserv'; | |
3. Startup using glassfish alias | |
4. Go to console: http://localhost:4848/ | |
5. Under Resources > JMS Resources > Connection Factories, create a new queue connection factory e.g. jms/testQueueConnectionFactory | |
6. Under Resources > JMS Resources > Connection Factories, create a new topic connection factory e.g. jms/testTopicConnectionFactory | |
7. Under Resources > JMS Resources > Destination Resources, create a new queue e.g. jms/testQueue | |
8. Under Resources > JMS Resources > Destination Resources, create a new topic e.g. jms/testTopic | |
Queue / Topic Client Setup (for glassfish) | |
1. Create files from: http://docs.oracle.com/javaee/1.3/jms/tutorial/1_3_1-fcs/doc/client.html | |
2. Change connection factory, queue and topic names to those created in glassfish | |
3. Compile them (Needed CLASSPATH as above to get compile / run to work) | |
To run: | |
java SimpleQueueReceiver jms/testQueue //Will end once message received | |
java SimpleQueueSender jms/testQueue <num> | |
java SimpleTopicSubscriber jms/testTopic <num> //Will wait and listen (can have multiple) | |
java SimpleTopicPublisher jms/testTopic | |
Client basics: | |
Create context | |
Lookup connection factory and queue or topic (by name) | |
Create connection, create session... | |
ActiveMQ Setup | |
wget http://www.apache.org/dyn/closer.cgi?path=/activemq/5.11.1/apache-activemq-5.11.1-bin.tar.gz | |
Move to apps | |
Untar in apps | |
Check executable permissions | |
Run from apps/apache-ac.... | |
bin/activemq | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment