connecters in activemq
DESCRIPTION
Understanding of JMS in ActiveMQ What are Network of BrokersHow to configure Connectors Using Various Protocols in ActiveMQTRANSCRIPT
ActiveMQ Messaging Services
Using ActiveMQ Why and When ActiveMQ was meant to be used as the JMS spec intended for remote communications
between distributed applications
ActiveMQ is used in the environment where applications need to overcome the agenda of tight
coupling
Asynchronous calls can be made easy in the loosely coupled applications ie Just fire and forget
No need to worry about how the application will handle the calls
Message is send to MOM() in a one-way fashion
When To Use ActiveMQ
Heterogeneous Application Integration
ActiveMQ is a tool with cross-language capabilities Basically it is an ActiveMQ broker is written in java
so it basically provides a Java client naturally But other than that it also provides a multi language client
support like c c++ NET Pearl PHP and many more
Loosen Couple between applications
Previously applications with RPC were believed to be very safe as message transmission and its
conformation plays a vital role in it But ActiveMQ change the acceptance of asynchronous scenario ie
one just need to send the message and need not to worry about it retrieval This decreases its
interdependency and makes it more loosely coupled and flexible That saves much of time over
interdependent systems Components use fire and forget kind of mechanism
Event Driven Architecture
The decoupled asynchronous style of architecture described allows broker itself to manage many clients
via tuning additional memory location and so on (known Vertical Scalability) Instead of rely on adding
number of broker nodes relying upon adding and handling the clients
Features of ActiveMQ
Active MQ is messaging service used for communication over various platforms ActivceMQ has
following features
JMS Compliance
ActiveMQ is an implementation of JMS 11 spec JMS provide guaranties like synchronous and
Asynchronous Messaging services once and once only message delivery message durability for
subscribers and more
Connectivity
It provides a wide range of support to protocol like Https Ip multicast SSL STOMP TCP UDP
XMPP and more Support to such wide range protocol increases its usability
Integration with application servers and Secured
ActiveMQ is much flexible as it provides a wide integration for application servers Also for security it
provides JAAS login modules and uses property files for authorization and authentication
Various client API
It provides a various client support for languages other than Java like cc++ NET Pearl PHP
Python Ruby and more
Clustering
Many ActiveMQ tools can provide a powerful set of features such as working of many ActiveMQ brokers
together that forms federated network of brokers
Dramatically Simplified Administration
ActiveMQ after years of monitoring provides a simplified administration tool for control of messages
This administration tool is so simple to look after that no extra resource is allocated for it
Understanding Message-oriented Middleware Message Oriented Middleware has played an important role in software communication in
asynchronous loosely-coupled reliable scalable and secure manner among distributed applications
MOMrsquos are acting as a message mediator between Message senders and receivers At high level
messages are business information that are transferred from sender to receiver using MOM that are
known as destinations
Both sender and receiver need not to get connected at same time MOM takes the message from sender
and sends to relevant receiver based on its destination address based on the availability of that user
This is how MOM helps in achieving loose-coupling And this is what recommended as asynchronous
messaging
Also the beneficiary part of MOM is that it provides a wide support to protocols HTTPS multicast SSL
TCPIP UDP and more
Java Messaging Services (JMS)
Java Messaging services is an API that is developed using Java client but still hides the complexity and
supports many other clients for implementations Like NET Ruby Pearl PHP etc
JMS provided many artifacts in world of messaging like
JMS Client [Pure Java client implementation]
NON-JMS Client [App written using Native JMS client]
JMS Producer [Client app that creates and sends JMS messages]
JMS Consumer [Client app that receives and processes JMS messages]
JMS Provider [Implementation interface in Java]
JMS Message
JMS Domains [P2P and publishSubscribe]
Java Message in JMS is made of 2 following things
Headers
o JMSCorrelationID o JMSDeliveryMode o JMSDestination o JMSExpiration o JMSMessageID o JMSPriority o JMSRedelivered o JMSReployTo o JMSTimestamp o JMSType
Payload
o It is just the content of the message the actual content
JMS Message Properties
JMSXAppIDmdashIdentifies the application sending the message
JMSXConsumerTXIDmdashThe transaction identifier for the transaction within which this message was consumed
JMSXDeliveryCountmdashThe number of message delivery attempts
JMSXGroupIDmdashThe message group of which this message is a part
JMSXGroupSeqmdashThe sequence number of this message within the group
JMSXProducerTXIDmdashThe transaction identifier for the transaction within which
this message was produced
JMSXRcvTimestampmdashThe time the JMS provider delivered the message to the consumer
JMSXStatemdashUsed to define a provider-specific state
JMSXUserID mdashIdentifies the user sending the message
JMS Message Body
MessagemdashThe base message type Used to send a message with no payload only headers and properties Typically used for simple event notification
TextMessage mdashA message whose payload is a String Commonly used to send simple textual and XML data
MapMessage mdashUses a set of namevalue pairs as its payload The names are of type String and the values are a Java primitive type
BytesMessage mdashUsed to contain an array of uninterrupted bytes as the payload
StreamMessagemdashA message with a payload containing a stream of primitive Java types thatrsquos filled and read sequentially
ObjectMessagemdashUsed to hold a serializable Java object as its payload Usually used for complex Java objects Also supports Java collections
JMS Domains
Persistent
Non-Persistent
Java Messaging Application Creation Steps
1 Acquire a JMS connection factory 2 Create a JMS connection using the connection factory 3 Start the JMS connection 4 Create a JMS session from the connection 5 Acquire a JMS destination 6 Create a JMS producer OR a Create a JMS producer b Create a JMS message and address it to a destination 7 Create a JMS consumer a Create a JMS consumer b Optionally register a JMS message listener 8 Send or receive JMS message(s) 9 Close all JMS resources (connection session producer consumer and so forth)
ActiveMQ Connectors
Understanding Connector URI
Itrsquos a compact string of characters that are used to refer a resource
Basically every URI has a following string resource ltschemegtltscheme-specific-partgt for ex
mailtoabcactivemqapacheorg
Where mailto ndash is scheme and Scheme-Specific-Part is the actual mail address
As we saw in previous examples that tcplocalhost61616trace=true ActiveMQ comes with the
concept of composite URI A composite URI automatically reconnects to another URI over failure of first
resource URI Ex static(tcphost161616tcphost261616)
HERE ABOVE STATIC IS lsquoSCHEMErsquo AND THERE ARE TWO PATHS
Note- White Space are not supported in composite URI
Transport Connectors
Transport connectors are used to send messages and receive messages fromto broker
Configuring Transport Connectors
Let us take that same portfolio example take a look at ActiveMQ demo configuration file
(confactivemq-demoxml)
lttransportConnectorsgt
lttransport-connector name=openwire uri=rdquotcplocalhost61616rdquogt
lttransportConnector name=ssl uri=ssllocalhost61617gt
lttransportConnector name=stomp uri=stomplocalhost61613gt
lttransportConnector name=xmpp uri=xmpplocalhost61222gt
lttransportConnectorsgt
Following code should be enough to get on transport connectors
ActiveMQConnectionFactory factory =
new ActiveMQConnectionFactory(tcplocalhost61616)
Connection connection = factorycreateConnection()
connectionstart()
Session session =
connectioncreateSession(false SessionAUTO_ACKNOWLEDGE)
Protocols
TCP [Transmission Control Protocol]
TCP has its own benefits of transferring data over peer to peer over years of long time we are relying on
TCP for successfully and securely sending data over Network
In TCP for sending messages in JMS we need to serialize messages in an suitable form ie They must be
serialized in and out as byte sequence to be sent over the wire protocol The default protocol used in
ActiveMQ is wire protocol
Syntax
Tcphostnameportkey=valueampkey=value
The following snippet of code needs to be added into the default configuration
lttransportConnectorsgt
lttransportConnector name=tcprdquo uri=tcplocalhost61616trace=truegt
lttransportConnectorsgt
mvn execjava -DexecmainClass=orgapacheactivemqbookch4Consumer -
Dexecargs=tcplocalhost61616 CSCO ORCL
Benefits of TCP
Efficiency
Since TCP uses open wire protocol for converting and receiving bytes over network It is very
efficient in terms of usage and performance
Reliability
Messages wonrsquot be lost over network
NIO [New IO Api Protocol]
New Input Output connector is not the replacement of traditional Java IO library It was an alternative
approach to network programming and access to some low-level IO operations of modern operating
systems
In all NIO is same as TCP the only difference is in its implementation TCP uses internally openwire that
makes it more secure and is implemented using transport API where as NIO connector is implemented
using NIO API
When there are so many clients wants to get connected to broker and the system may feel like
completely overloaded from clients at that moment NIO protocol can be used
Syntax
niohostnameportkey=value
Example [Add to the default configuration] ie confactivemqxml
lttransportConnectorsgt
lttransportConnector name=tcp uri=tcplocalhost61616trace=true gt
lttransportConnector name=nio uri=niolocalhost61618trace=true gt
lttransportConnectorsgt
Note - NIO connector must not set on the client side as it is server specific client needs to use TCP and
since server needs to maintain load and other issues we need to use NIO at server side
Letrsquos simply execute the example using following steps
Step 1
Goto confactivemqxml
Step 2
Add the Following lines in the lttransportconnectorsgt
lttransportConnector name=nio uri=niolocalhost61618trace=true gt
Step 3
Restart ActiveMQ Server
Step 4
Execute Publisher [mvn execjava -DexecmainClass=orgapacheactivemqbookch4Publisher
-Dexecargs=niolocalhost61618 CSCO ORCL]
Step 5
Execute Consumer [mvn execjava -DexecmainClass=orgapacheactivemqbookch4Consumer
-Dexecargs=tcplocalhost61616 CSCO ORCL]
Just look at this issue will help a lot in getting the beneath of
lsquohttpactivemq2283324n4nabblecomProblem-with-NIO-protocol-td3540710htmlrsquo
UDP [User Datagram Protocol]
UDP was designed basically for faster transmission of data over network Situations where the
transferring of data is more important than its reliability in such cases UDP is preferable [Voip Online
Gaming]
Syntax
udphostnameportkey=value
Example Add following code lines to execute this UDP example
Edit [confactivemqxml]
lttransportconnectorsgt
lttransportConnector name=udp uri=udplocalhost61618trace=true gt
lttransportconnectorsgt
Letrsquos simply execute the example using following steps
Step 1
Goto confactivemqxml
Step 2
Add the Following lines in the lttransportconnectorsgt
lttransportConnector name=udp uri=udplocalhost61618trace=true gt
Step 3
Restart ActiveMQ Server
Step 4
Execute Publisher [mvn execjava -DexecmainClass=orgapacheactivemqbookch4Publisher
-Dexecargs=udplocalhost61618 CSCO ORCL]
Step 5
Execute Consumer [mvn execjava -DexecmainClass=orgapacheactivemqbookch4Consumer
-Dexecargs=tcplocalhost61616 CSCO ORCL]
IT completely depends on the user which protocol needs to be used
SSL [Secure Socket Layer]
In situations where security is more concern that transmission SSL is a secure protocol need to be used
in such situations It internally uses the TCP so it covers all the basic TCP properties apart from it it
encrypts the data on TCP channel makes it more secure
It uses SSL transport connector that adds an SSL layer over TCP It provides an encrypted communication
over client and brokers
Syntax
sslhostnameportkey=value
Example Add following code lines to execute this SSL example
Edit [confactivemqxml]
lttransportConnectorsgt
lttransportConnector name=ssl uri=ssllocalhost61617trace=true gt
lttransportConnectorsgt
Here executing example covers some extra steps since we need to create certificates (keystores) for the
client
Step 1
Goto confactivemqxml
Step 2
Add the Following lines in the lttransportconnectorsgt
lttransportConnector name=ssl uri=ssllocalhost61617trace=true gt
Step 3
Restart ActiveMQ Server
Step 4
Execute Consumer [mvn execjava -DexecmainClass=orgapacheactivemqbookch4Consumer
-Dexecargs=ssllocalhost61617 CSCO ORCL] =gt Gives Error
Note - To resolve this error we need to provide some basic system properties
javaxnetsslkeyStoremdashDefines which keystore the client should use
javaxnetsslkeyStorePasswordmdashDefines an appropriate password for the keystore
javaxnetssltrustStoremdashDefines an appropriate truststore the client should use
Step 4
Execute Following Command for Publisher
mvn -DjavaxnetsslkeyStore=$ACTIVEMQ_HOMEconfclientks -
DjavaxnetsslkeyStorePassword=password -
DjavaxnetssltrustStore=$ACTIVEMQ_HOMEconfclientts execjava -
DexecmainClass=orgapacheactivemqbookch4Publisher -Dexecargs=ssllocalhost61617 CSCO
ORCL
Step 5
Execute Following Command for Consumer
mvn -DjavaxnetsslkeyStore=$ACTIVEMQ_HOMEconfclientks -
DjavaxnetsslkeyStorePassword=password -
DjavaxnetssltrustStore=$ACTIVEMQ_HOMEconfclientts execjava
DexecmainClass=orgapacheactivemqbookch4Consumer -Dexecargs=ssllocalhost61617 CSCO
ORCL
It basically needs two types stored keys and certificates The first so called is keystore(brokerks) and the
another is truststore (brokerts)
Note - You can also enable and disable the SSL ciphers
ACTIVEMQ_HOMEconfactivemqxml
Add Following Lines of Code
lttransportConnectorsgt
lttransportConnector
name=ssl uri=ssllocalhost61617transportenabledCipherSuites=SSL_RSA_WITH_RC4_128_SHA
gt
lttransportConnectorsgt
Hypertext Transfer Protocol [HttpHttps]
Systems where firewalls are configured to allow basic services such as web access and email In those
scenarios ActiveMQ comes into existence
ActiveMQ implements the HTTP Transport connector which provides the xml formatted data to broker
using HTTP Protocol
Syntax HTTP HTTPS
httphostnameportkey=value
httpshostnameportkey=value
Example Add following code lines to execute this SSL example
Edit [confactivemqxml]
lttransportConnectorsgt
lttransportConnector name=tcp uri=tcplocalhost61616trace=truegt
lttransportConnector name=http uri=httplocalhost8080trace=true gt
lttransportConnectorsgt
Note- Basically there are two transports that are listening to port 8080 TCP transport and HTTP
Transport
ltdependencygt
ltgroupIdgtorgapacheactivemqltgroupIdgt
ltartifactIdgtactivemq-optionalltartifactIdgt
ltversiongt541ltversiongt
ltdependencygt
ActiveMQ is an implementation of JMS 11 spec JMS provide guaranties like synchronous and
Asynchronous Messaging services once and once only message delivery message durability for
subscribers and more
Connectivity
It provides a wide range of support to protocol like Https Ip multicast SSL STOMP TCP UDP
XMPP and more Support to such wide range protocol increases its usability
Integration with application servers and Secured
ActiveMQ is much flexible as it provides a wide integration for application servers Also for security it
provides JAAS login modules and uses property files for authorization and authentication
Various client API
It provides a various client support for languages other than Java like cc++ NET Pearl PHP
Python Ruby and more
Clustering
Many ActiveMQ tools can provide a powerful set of features such as working of many ActiveMQ brokers
together that forms federated network of brokers
Dramatically Simplified Administration
ActiveMQ after years of monitoring provides a simplified administration tool for control of messages
This administration tool is so simple to look after that no extra resource is allocated for it
Understanding Message-oriented Middleware Message Oriented Middleware has played an important role in software communication in
asynchronous loosely-coupled reliable scalable and secure manner among distributed applications
MOMrsquos are acting as a message mediator between Message senders and receivers At high level
messages are business information that are transferred from sender to receiver using MOM that are
known as destinations
Both sender and receiver need not to get connected at same time MOM takes the message from sender
and sends to relevant receiver based on its destination address based on the availability of that user
This is how MOM helps in achieving loose-coupling And this is what recommended as asynchronous
messaging
Also the beneficiary part of MOM is that it provides a wide support to protocols HTTPS multicast SSL
TCPIP UDP and more
Java Messaging Services (JMS)
Java Messaging services is an API that is developed using Java client but still hides the complexity and
supports many other clients for implementations Like NET Ruby Pearl PHP etc
JMS provided many artifacts in world of messaging like
JMS Client [Pure Java client implementation]
NON-JMS Client [App written using Native JMS client]
JMS Producer [Client app that creates and sends JMS messages]
JMS Consumer [Client app that receives and processes JMS messages]
JMS Provider [Implementation interface in Java]
JMS Message
JMS Domains [P2P and publishSubscribe]
Java Message in JMS is made of 2 following things
Headers
o JMSCorrelationID o JMSDeliveryMode o JMSDestination o JMSExpiration o JMSMessageID o JMSPriority o JMSRedelivered o JMSReployTo o JMSTimestamp o JMSType
Payload
o It is just the content of the message the actual content
JMS Message Properties
JMSXAppIDmdashIdentifies the application sending the message
JMSXConsumerTXIDmdashThe transaction identifier for the transaction within which this message was consumed
JMSXDeliveryCountmdashThe number of message delivery attempts
JMSXGroupIDmdashThe message group of which this message is a part
JMSXGroupSeqmdashThe sequence number of this message within the group
JMSXProducerTXIDmdashThe transaction identifier for the transaction within which
this message was produced
JMSXRcvTimestampmdashThe time the JMS provider delivered the message to the consumer
JMSXStatemdashUsed to define a provider-specific state
JMSXUserID mdashIdentifies the user sending the message
JMS Message Body
MessagemdashThe base message type Used to send a message with no payload only headers and properties Typically used for simple event notification
TextMessage mdashA message whose payload is a String Commonly used to send simple textual and XML data
MapMessage mdashUses a set of namevalue pairs as its payload The names are of type String and the values are a Java primitive type
BytesMessage mdashUsed to contain an array of uninterrupted bytes as the payload
StreamMessagemdashA message with a payload containing a stream of primitive Java types thatrsquos filled and read sequentially
ObjectMessagemdashUsed to hold a serializable Java object as its payload Usually used for complex Java objects Also supports Java collections
JMS Domains
Persistent
Non-Persistent
Java Messaging Application Creation Steps
1 Acquire a JMS connection factory 2 Create a JMS connection using the connection factory 3 Start the JMS connection 4 Create a JMS session from the connection 5 Acquire a JMS destination 6 Create a JMS producer OR a Create a JMS producer b Create a JMS message and address it to a destination 7 Create a JMS consumer a Create a JMS consumer b Optionally register a JMS message listener 8 Send or receive JMS message(s) 9 Close all JMS resources (connection session producer consumer and so forth)
ActiveMQ Connectors
Understanding Connector URI
Itrsquos a compact string of characters that are used to refer a resource
Basically every URI has a following string resource ltschemegtltscheme-specific-partgt for ex
mailtoabcactivemqapacheorg
Where mailto ndash is scheme and Scheme-Specific-Part is the actual mail address
As we saw in previous examples that tcplocalhost61616trace=true ActiveMQ comes with the
concept of composite URI A composite URI automatically reconnects to another URI over failure of first
resource URI Ex static(tcphost161616tcphost261616)
HERE ABOVE STATIC IS lsquoSCHEMErsquo AND THERE ARE TWO PATHS
Note- White Space are not supported in composite URI
Transport Connectors
Transport connectors are used to send messages and receive messages fromto broker
Configuring Transport Connectors
Let us take that same portfolio example take a look at ActiveMQ demo configuration file
(confactivemq-demoxml)
lttransportConnectorsgt
lttransport-connector name=openwire uri=rdquotcplocalhost61616rdquogt
lttransportConnector name=ssl uri=ssllocalhost61617gt
lttransportConnector name=stomp uri=stomplocalhost61613gt
lttransportConnector name=xmpp uri=xmpplocalhost61222gt
lttransportConnectorsgt
Following code should be enough to get on transport connectors
ActiveMQConnectionFactory factory =
new ActiveMQConnectionFactory(tcplocalhost61616)
Connection connection = factorycreateConnection()
connectionstart()
Session session =
connectioncreateSession(false SessionAUTO_ACKNOWLEDGE)
Protocols
TCP [Transmission Control Protocol]
TCP has its own benefits of transferring data over peer to peer over years of long time we are relying on
TCP for successfully and securely sending data over Network
In TCP for sending messages in JMS we need to serialize messages in an suitable form ie They must be
serialized in and out as byte sequence to be sent over the wire protocol The default protocol used in
ActiveMQ is wire protocol
Syntax
Tcphostnameportkey=valueampkey=value
The following snippet of code needs to be added into the default configuration
lttransportConnectorsgt
lttransportConnector name=tcprdquo uri=tcplocalhost61616trace=truegt
lttransportConnectorsgt
mvn execjava -DexecmainClass=orgapacheactivemqbookch4Consumer -
Dexecargs=tcplocalhost61616 CSCO ORCL
Benefits of TCP
Efficiency
Since TCP uses open wire protocol for converting and receiving bytes over network It is very
efficient in terms of usage and performance
Reliability
Messages wonrsquot be lost over network
NIO [New IO Api Protocol]
New Input Output connector is not the replacement of traditional Java IO library It was an alternative
approach to network programming and access to some low-level IO operations of modern operating
systems
In all NIO is same as TCP the only difference is in its implementation TCP uses internally openwire that
makes it more secure and is implemented using transport API where as NIO connector is implemented
using NIO API
When there are so many clients wants to get connected to broker and the system may feel like
completely overloaded from clients at that moment NIO protocol can be used
Syntax
niohostnameportkey=value
Example [Add to the default configuration] ie confactivemqxml
lttransportConnectorsgt
lttransportConnector name=tcp uri=tcplocalhost61616trace=true gt
lttransportConnector name=nio uri=niolocalhost61618trace=true gt
lttransportConnectorsgt
Note - NIO connector must not set on the client side as it is server specific client needs to use TCP and
since server needs to maintain load and other issues we need to use NIO at server side
Letrsquos simply execute the example using following steps
Step 1
Goto confactivemqxml
Step 2
Add the Following lines in the lttransportconnectorsgt
lttransportConnector name=nio uri=niolocalhost61618trace=true gt
Step 3
Restart ActiveMQ Server
Step 4
Execute Publisher [mvn execjava -DexecmainClass=orgapacheactivemqbookch4Publisher
-Dexecargs=niolocalhost61618 CSCO ORCL]
Step 5
Execute Consumer [mvn execjava -DexecmainClass=orgapacheactivemqbookch4Consumer
-Dexecargs=tcplocalhost61616 CSCO ORCL]
Just look at this issue will help a lot in getting the beneath of
lsquohttpactivemq2283324n4nabblecomProblem-with-NIO-protocol-td3540710htmlrsquo
UDP [User Datagram Protocol]
UDP was designed basically for faster transmission of data over network Situations where the
transferring of data is more important than its reliability in such cases UDP is preferable [Voip Online
Gaming]
Syntax
udphostnameportkey=value
Example Add following code lines to execute this UDP example
Edit [confactivemqxml]
lttransportconnectorsgt
lttransportConnector name=udp uri=udplocalhost61618trace=true gt
lttransportconnectorsgt
Letrsquos simply execute the example using following steps
Step 1
Goto confactivemqxml
Step 2
Add the Following lines in the lttransportconnectorsgt
lttransportConnector name=udp uri=udplocalhost61618trace=true gt
Step 3
Restart ActiveMQ Server
Step 4
Execute Publisher [mvn execjava -DexecmainClass=orgapacheactivemqbookch4Publisher
-Dexecargs=udplocalhost61618 CSCO ORCL]
Step 5
Execute Consumer [mvn execjava -DexecmainClass=orgapacheactivemqbookch4Consumer
-Dexecargs=tcplocalhost61616 CSCO ORCL]
IT completely depends on the user which protocol needs to be used
SSL [Secure Socket Layer]
In situations where security is more concern that transmission SSL is a secure protocol need to be used
in such situations It internally uses the TCP so it covers all the basic TCP properties apart from it it
encrypts the data on TCP channel makes it more secure
It uses SSL transport connector that adds an SSL layer over TCP It provides an encrypted communication
over client and brokers
Syntax
sslhostnameportkey=value
Example Add following code lines to execute this SSL example
Edit [confactivemqxml]
lttransportConnectorsgt
lttransportConnector name=ssl uri=ssllocalhost61617trace=true gt
lttransportConnectorsgt
Here executing example covers some extra steps since we need to create certificates (keystores) for the
client
Step 1
Goto confactivemqxml
Step 2
Add the Following lines in the lttransportconnectorsgt
lttransportConnector name=ssl uri=ssllocalhost61617trace=true gt
Step 3
Restart ActiveMQ Server
Step 4
Execute Consumer [mvn execjava -DexecmainClass=orgapacheactivemqbookch4Consumer
-Dexecargs=ssllocalhost61617 CSCO ORCL] =gt Gives Error
Note - To resolve this error we need to provide some basic system properties
javaxnetsslkeyStoremdashDefines which keystore the client should use
javaxnetsslkeyStorePasswordmdashDefines an appropriate password for the keystore
javaxnetssltrustStoremdashDefines an appropriate truststore the client should use
Step 4
Execute Following Command for Publisher
mvn -DjavaxnetsslkeyStore=$ACTIVEMQ_HOMEconfclientks -
DjavaxnetsslkeyStorePassword=password -
DjavaxnetssltrustStore=$ACTIVEMQ_HOMEconfclientts execjava -
DexecmainClass=orgapacheactivemqbookch4Publisher -Dexecargs=ssllocalhost61617 CSCO
ORCL
Step 5
Execute Following Command for Consumer
mvn -DjavaxnetsslkeyStore=$ACTIVEMQ_HOMEconfclientks -
DjavaxnetsslkeyStorePassword=password -
DjavaxnetssltrustStore=$ACTIVEMQ_HOMEconfclientts execjava
DexecmainClass=orgapacheactivemqbookch4Consumer -Dexecargs=ssllocalhost61617 CSCO
ORCL
It basically needs two types stored keys and certificates The first so called is keystore(brokerks) and the
another is truststore (brokerts)
Note - You can also enable and disable the SSL ciphers
ACTIVEMQ_HOMEconfactivemqxml
Add Following Lines of Code
lttransportConnectorsgt
lttransportConnector
name=ssl uri=ssllocalhost61617transportenabledCipherSuites=SSL_RSA_WITH_RC4_128_SHA
gt
lttransportConnectorsgt
Hypertext Transfer Protocol [HttpHttps]
Systems where firewalls are configured to allow basic services such as web access and email In those
scenarios ActiveMQ comes into existence
ActiveMQ implements the HTTP Transport connector which provides the xml formatted data to broker
using HTTP Protocol
Syntax HTTP HTTPS
httphostnameportkey=value
httpshostnameportkey=value
Example Add following code lines to execute this SSL example
Edit [confactivemqxml]
lttransportConnectorsgt
lttransportConnector name=tcp uri=tcplocalhost61616trace=truegt
lttransportConnector name=http uri=httplocalhost8080trace=true gt
lttransportConnectorsgt
Note- Basically there are two transports that are listening to port 8080 TCP transport and HTTP
Transport
ltdependencygt
ltgroupIdgtorgapacheactivemqltgroupIdgt
ltartifactIdgtactivemq-optionalltartifactIdgt
ltversiongt541ltversiongt
ltdependencygt
Java Messaging Services (JMS)
Java Messaging services is an API that is developed using Java client but still hides the complexity and
supports many other clients for implementations Like NET Ruby Pearl PHP etc
JMS provided many artifacts in world of messaging like
JMS Client [Pure Java client implementation]
NON-JMS Client [App written using Native JMS client]
JMS Producer [Client app that creates and sends JMS messages]
JMS Consumer [Client app that receives and processes JMS messages]
JMS Provider [Implementation interface in Java]
JMS Message
JMS Domains [P2P and publishSubscribe]
Java Message in JMS is made of 2 following things
Headers
o JMSCorrelationID o JMSDeliveryMode o JMSDestination o JMSExpiration o JMSMessageID o JMSPriority o JMSRedelivered o JMSReployTo o JMSTimestamp o JMSType
Payload
o It is just the content of the message the actual content
JMS Message Properties
JMSXAppIDmdashIdentifies the application sending the message
JMSXConsumerTXIDmdashThe transaction identifier for the transaction within which this message was consumed
JMSXDeliveryCountmdashThe number of message delivery attempts
JMSXGroupIDmdashThe message group of which this message is a part
JMSXGroupSeqmdashThe sequence number of this message within the group
JMSXProducerTXIDmdashThe transaction identifier for the transaction within which
this message was produced
JMSXRcvTimestampmdashThe time the JMS provider delivered the message to the consumer
JMSXStatemdashUsed to define a provider-specific state
JMSXUserID mdashIdentifies the user sending the message
JMS Message Body
MessagemdashThe base message type Used to send a message with no payload only headers and properties Typically used for simple event notification
TextMessage mdashA message whose payload is a String Commonly used to send simple textual and XML data
MapMessage mdashUses a set of namevalue pairs as its payload The names are of type String and the values are a Java primitive type
BytesMessage mdashUsed to contain an array of uninterrupted bytes as the payload
StreamMessagemdashA message with a payload containing a stream of primitive Java types thatrsquos filled and read sequentially
ObjectMessagemdashUsed to hold a serializable Java object as its payload Usually used for complex Java objects Also supports Java collections
JMS Domains
Persistent
Non-Persistent
Java Messaging Application Creation Steps
1 Acquire a JMS connection factory 2 Create a JMS connection using the connection factory 3 Start the JMS connection 4 Create a JMS session from the connection 5 Acquire a JMS destination 6 Create a JMS producer OR a Create a JMS producer b Create a JMS message and address it to a destination 7 Create a JMS consumer a Create a JMS consumer b Optionally register a JMS message listener 8 Send or receive JMS message(s) 9 Close all JMS resources (connection session producer consumer and so forth)
ActiveMQ Connectors
Understanding Connector URI
Itrsquos a compact string of characters that are used to refer a resource
Basically every URI has a following string resource ltschemegtltscheme-specific-partgt for ex
mailtoabcactivemqapacheorg
Where mailto ndash is scheme and Scheme-Specific-Part is the actual mail address
As we saw in previous examples that tcplocalhost61616trace=true ActiveMQ comes with the
concept of composite URI A composite URI automatically reconnects to another URI over failure of first
resource URI Ex static(tcphost161616tcphost261616)
HERE ABOVE STATIC IS lsquoSCHEMErsquo AND THERE ARE TWO PATHS
Note- White Space are not supported in composite URI
Transport Connectors
Transport connectors are used to send messages and receive messages fromto broker
Configuring Transport Connectors
Let us take that same portfolio example take a look at ActiveMQ demo configuration file
(confactivemq-demoxml)
lttransportConnectorsgt
lttransport-connector name=openwire uri=rdquotcplocalhost61616rdquogt
lttransportConnector name=ssl uri=ssllocalhost61617gt
lttransportConnector name=stomp uri=stomplocalhost61613gt
lttransportConnector name=xmpp uri=xmpplocalhost61222gt
lttransportConnectorsgt
Following code should be enough to get on transport connectors
ActiveMQConnectionFactory factory =
new ActiveMQConnectionFactory(tcplocalhost61616)
Connection connection = factorycreateConnection()
connectionstart()
Session session =
connectioncreateSession(false SessionAUTO_ACKNOWLEDGE)
Protocols
TCP [Transmission Control Protocol]
TCP has its own benefits of transferring data over peer to peer over years of long time we are relying on
TCP for successfully and securely sending data over Network
In TCP for sending messages in JMS we need to serialize messages in an suitable form ie They must be
serialized in and out as byte sequence to be sent over the wire protocol The default protocol used in
ActiveMQ is wire protocol
Syntax
Tcphostnameportkey=valueampkey=value
The following snippet of code needs to be added into the default configuration
lttransportConnectorsgt
lttransportConnector name=tcprdquo uri=tcplocalhost61616trace=truegt
lttransportConnectorsgt
mvn execjava -DexecmainClass=orgapacheactivemqbookch4Consumer -
Dexecargs=tcplocalhost61616 CSCO ORCL
Benefits of TCP
Efficiency
Since TCP uses open wire protocol for converting and receiving bytes over network It is very
efficient in terms of usage and performance
Reliability
Messages wonrsquot be lost over network
NIO [New IO Api Protocol]
New Input Output connector is not the replacement of traditional Java IO library It was an alternative
approach to network programming and access to some low-level IO operations of modern operating
systems
In all NIO is same as TCP the only difference is in its implementation TCP uses internally openwire that
makes it more secure and is implemented using transport API where as NIO connector is implemented
using NIO API
When there are so many clients wants to get connected to broker and the system may feel like
completely overloaded from clients at that moment NIO protocol can be used
Syntax
niohostnameportkey=value
Example [Add to the default configuration] ie confactivemqxml
lttransportConnectorsgt
lttransportConnector name=tcp uri=tcplocalhost61616trace=true gt
lttransportConnector name=nio uri=niolocalhost61618trace=true gt
lttransportConnectorsgt
Note - NIO connector must not set on the client side as it is server specific client needs to use TCP and
since server needs to maintain load and other issues we need to use NIO at server side
Letrsquos simply execute the example using following steps
Step 1
Goto confactivemqxml
Step 2
Add the Following lines in the lttransportconnectorsgt
lttransportConnector name=nio uri=niolocalhost61618trace=true gt
Step 3
Restart ActiveMQ Server
Step 4
Execute Publisher [mvn execjava -DexecmainClass=orgapacheactivemqbookch4Publisher
-Dexecargs=niolocalhost61618 CSCO ORCL]
Step 5
Execute Consumer [mvn execjava -DexecmainClass=orgapacheactivemqbookch4Consumer
-Dexecargs=tcplocalhost61616 CSCO ORCL]
Just look at this issue will help a lot in getting the beneath of
lsquohttpactivemq2283324n4nabblecomProblem-with-NIO-protocol-td3540710htmlrsquo
UDP [User Datagram Protocol]
UDP was designed basically for faster transmission of data over network Situations where the
transferring of data is more important than its reliability in such cases UDP is preferable [Voip Online
Gaming]
Syntax
udphostnameportkey=value
Example Add following code lines to execute this UDP example
Edit [confactivemqxml]
lttransportconnectorsgt
lttransportConnector name=udp uri=udplocalhost61618trace=true gt
lttransportconnectorsgt
Letrsquos simply execute the example using following steps
Step 1
Goto confactivemqxml
Step 2
Add the Following lines in the lttransportconnectorsgt
lttransportConnector name=udp uri=udplocalhost61618trace=true gt
Step 3
Restart ActiveMQ Server
Step 4
Execute Publisher [mvn execjava -DexecmainClass=orgapacheactivemqbookch4Publisher
-Dexecargs=udplocalhost61618 CSCO ORCL]
Step 5
Execute Consumer [mvn execjava -DexecmainClass=orgapacheactivemqbookch4Consumer
-Dexecargs=tcplocalhost61616 CSCO ORCL]
IT completely depends on the user which protocol needs to be used
SSL [Secure Socket Layer]
In situations where security is more concern that transmission SSL is a secure protocol need to be used
in such situations It internally uses the TCP so it covers all the basic TCP properties apart from it it
encrypts the data on TCP channel makes it more secure
It uses SSL transport connector that adds an SSL layer over TCP It provides an encrypted communication
over client and brokers
Syntax
sslhostnameportkey=value
Example Add following code lines to execute this SSL example
Edit [confactivemqxml]
lttransportConnectorsgt
lttransportConnector name=ssl uri=ssllocalhost61617trace=true gt
lttransportConnectorsgt
Here executing example covers some extra steps since we need to create certificates (keystores) for the
client
Step 1
Goto confactivemqxml
Step 2
Add the Following lines in the lttransportconnectorsgt
lttransportConnector name=ssl uri=ssllocalhost61617trace=true gt
Step 3
Restart ActiveMQ Server
Step 4
Execute Consumer [mvn execjava -DexecmainClass=orgapacheactivemqbookch4Consumer
-Dexecargs=ssllocalhost61617 CSCO ORCL] =gt Gives Error
Note - To resolve this error we need to provide some basic system properties
javaxnetsslkeyStoremdashDefines which keystore the client should use
javaxnetsslkeyStorePasswordmdashDefines an appropriate password for the keystore
javaxnetssltrustStoremdashDefines an appropriate truststore the client should use
Step 4
Execute Following Command for Publisher
mvn -DjavaxnetsslkeyStore=$ACTIVEMQ_HOMEconfclientks -
DjavaxnetsslkeyStorePassword=password -
DjavaxnetssltrustStore=$ACTIVEMQ_HOMEconfclientts execjava -
DexecmainClass=orgapacheactivemqbookch4Publisher -Dexecargs=ssllocalhost61617 CSCO
ORCL
Step 5
Execute Following Command for Consumer
mvn -DjavaxnetsslkeyStore=$ACTIVEMQ_HOMEconfclientks -
DjavaxnetsslkeyStorePassword=password -
DjavaxnetssltrustStore=$ACTIVEMQ_HOMEconfclientts execjava
DexecmainClass=orgapacheactivemqbookch4Consumer -Dexecargs=ssllocalhost61617 CSCO
ORCL
It basically needs two types stored keys and certificates The first so called is keystore(brokerks) and the
another is truststore (brokerts)
Note - You can also enable and disable the SSL ciphers
ACTIVEMQ_HOMEconfactivemqxml
Add Following Lines of Code
lttransportConnectorsgt
lttransportConnector
name=ssl uri=ssllocalhost61617transportenabledCipherSuites=SSL_RSA_WITH_RC4_128_SHA
gt
lttransportConnectorsgt
Hypertext Transfer Protocol [HttpHttps]
Systems where firewalls are configured to allow basic services such as web access and email In those
scenarios ActiveMQ comes into existence
ActiveMQ implements the HTTP Transport connector which provides the xml formatted data to broker
using HTTP Protocol
Syntax HTTP HTTPS
httphostnameportkey=value
httpshostnameportkey=value
Example Add following code lines to execute this SSL example
Edit [confactivemqxml]
lttransportConnectorsgt
lttransportConnector name=tcp uri=tcplocalhost61616trace=truegt
lttransportConnector name=http uri=httplocalhost8080trace=true gt
lttransportConnectorsgt
Note- Basically there are two transports that are listening to port 8080 TCP transport and HTTP
Transport
ltdependencygt
ltgroupIdgtorgapacheactivemqltgroupIdgt
ltartifactIdgtactivemq-optionalltartifactIdgt
ltversiongt541ltversiongt
ltdependencygt
this message was produced
JMSXRcvTimestampmdashThe time the JMS provider delivered the message to the consumer
JMSXStatemdashUsed to define a provider-specific state
JMSXUserID mdashIdentifies the user sending the message
JMS Message Body
MessagemdashThe base message type Used to send a message with no payload only headers and properties Typically used for simple event notification
TextMessage mdashA message whose payload is a String Commonly used to send simple textual and XML data
MapMessage mdashUses a set of namevalue pairs as its payload The names are of type String and the values are a Java primitive type
BytesMessage mdashUsed to contain an array of uninterrupted bytes as the payload
StreamMessagemdashA message with a payload containing a stream of primitive Java types thatrsquos filled and read sequentially
ObjectMessagemdashUsed to hold a serializable Java object as its payload Usually used for complex Java objects Also supports Java collections
JMS Domains
Persistent
Non-Persistent
Java Messaging Application Creation Steps
1 Acquire a JMS connection factory 2 Create a JMS connection using the connection factory 3 Start the JMS connection 4 Create a JMS session from the connection 5 Acquire a JMS destination 6 Create a JMS producer OR a Create a JMS producer b Create a JMS message and address it to a destination 7 Create a JMS consumer a Create a JMS consumer b Optionally register a JMS message listener 8 Send or receive JMS message(s) 9 Close all JMS resources (connection session producer consumer and so forth)
ActiveMQ Connectors
Understanding Connector URI
Itrsquos a compact string of characters that are used to refer a resource
Basically every URI has a following string resource ltschemegtltscheme-specific-partgt for ex
mailtoabcactivemqapacheorg
Where mailto ndash is scheme and Scheme-Specific-Part is the actual mail address
As we saw in previous examples that tcplocalhost61616trace=true ActiveMQ comes with the
concept of composite URI A composite URI automatically reconnects to another URI over failure of first
resource URI Ex static(tcphost161616tcphost261616)
HERE ABOVE STATIC IS lsquoSCHEMErsquo AND THERE ARE TWO PATHS
Note- White Space are not supported in composite URI
Transport Connectors
Transport connectors are used to send messages and receive messages fromto broker
Configuring Transport Connectors
Let us take that same portfolio example take a look at ActiveMQ demo configuration file
(confactivemq-demoxml)
lttransportConnectorsgt
lttransport-connector name=openwire uri=rdquotcplocalhost61616rdquogt
lttransportConnector name=ssl uri=ssllocalhost61617gt
lttransportConnector name=stomp uri=stomplocalhost61613gt
lttransportConnector name=xmpp uri=xmpplocalhost61222gt
lttransportConnectorsgt
Following code should be enough to get on transport connectors
ActiveMQConnectionFactory factory =
new ActiveMQConnectionFactory(tcplocalhost61616)
Connection connection = factorycreateConnection()
connectionstart()
Session session =
connectioncreateSession(false SessionAUTO_ACKNOWLEDGE)
Protocols
TCP [Transmission Control Protocol]
TCP has its own benefits of transferring data over peer to peer over years of long time we are relying on
TCP for successfully and securely sending data over Network
In TCP for sending messages in JMS we need to serialize messages in an suitable form ie They must be
serialized in and out as byte sequence to be sent over the wire protocol The default protocol used in
ActiveMQ is wire protocol
Syntax
Tcphostnameportkey=valueampkey=value
The following snippet of code needs to be added into the default configuration
lttransportConnectorsgt
lttransportConnector name=tcprdquo uri=tcplocalhost61616trace=truegt
lttransportConnectorsgt
mvn execjava -DexecmainClass=orgapacheactivemqbookch4Consumer -
Dexecargs=tcplocalhost61616 CSCO ORCL
Benefits of TCP
Efficiency
Since TCP uses open wire protocol for converting and receiving bytes over network It is very
efficient in terms of usage and performance
Reliability
Messages wonrsquot be lost over network
NIO [New IO Api Protocol]
New Input Output connector is not the replacement of traditional Java IO library It was an alternative
approach to network programming and access to some low-level IO operations of modern operating
systems
In all NIO is same as TCP the only difference is in its implementation TCP uses internally openwire that
makes it more secure and is implemented using transport API where as NIO connector is implemented
using NIO API
When there are so many clients wants to get connected to broker and the system may feel like
completely overloaded from clients at that moment NIO protocol can be used
Syntax
niohostnameportkey=value
Example [Add to the default configuration] ie confactivemqxml
lttransportConnectorsgt
lttransportConnector name=tcp uri=tcplocalhost61616trace=true gt
lttransportConnector name=nio uri=niolocalhost61618trace=true gt
lttransportConnectorsgt
Note - NIO connector must not set on the client side as it is server specific client needs to use TCP and
since server needs to maintain load and other issues we need to use NIO at server side
Letrsquos simply execute the example using following steps
Step 1
Goto confactivemqxml
Step 2
Add the Following lines in the lttransportconnectorsgt
lttransportConnector name=nio uri=niolocalhost61618trace=true gt
Step 3
Restart ActiveMQ Server
Step 4
Execute Publisher [mvn execjava -DexecmainClass=orgapacheactivemqbookch4Publisher
-Dexecargs=niolocalhost61618 CSCO ORCL]
Step 5
Execute Consumer [mvn execjava -DexecmainClass=orgapacheactivemqbookch4Consumer
-Dexecargs=tcplocalhost61616 CSCO ORCL]
Just look at this issue will help a lot in getting the beneath of
lsquohttpactivemq2283324n4nabblecomProblem-with-NIO-protocol-td3540710htmlrsquo
UDP [User Datagram Protocol]
UDP was designed basically for faster transmission of data over network Situations where the
transferring of data is more important than its reliability in such cases UDP is preferable [Voip Online
Gaming]
Syntax
udphostnameportkey=value
Example Add following code lines to execute this UDP example
Edit [confactivemqxml]
lttransportconnectorsgt
lttransportConnector name=udp uri=udplocalhost61618trace=true gt
lttransportconnectorsgt
Letrsquos simply execute the example using following steps
Step 1
Goto confactivemqxml
Step 2
Add the Following lines in the lttransportconnectorsgt
lttransportConnector name=udp uri=udplocalhost61618trace=true gt
Step 3
Restart ActiveMQ Server
Step 4
Execute Publisher [mvn execjava -DexecmainClass=orgapacheactivemqbookch4Publisher
-Dexecargs=udplocalhost61618 CSCO ORCL]
Step 5
Execute Consumer [mvn execjava -DexecmainClass=orgapacheactivemqbookch4Consumer
-Dexecargs=tcplocalhost61616 CSCO ORCL]
IT completely depends on the user which protocol needs to be used
SSL [Secure Socket Layer]
In situations where security is more concern that transmission SSL is a secure protocol need to be used
in such situations It internally uses the TCP so it covers all the basic TCP properties apart from it it
encrypts the data on TCP channel makes it more secure
It uses SSL transport connector that adds an SSL layer over TCP It provides an encrypted communication
over client and brokers
Syntax
sslhostnameportkey=value
Example Add following code lines to execute this SSL example
Edit [confactivemqxml]
lttransportConnectorsgt
lttransportConnector name=ssl uri=ssllocalhost61617trace=true gt
lttransportConnectorsgt
Here executing example covers some extra steps since we need to create certificates (keystores) for the
client
Step 1
Goto confactivemqxml
Step 2
Add the Following lines in the lttransportconnectorsgt
lttransportConnector name=ssl uri=ssllocalhost61617trace=true gt
Step 3
Restart ActiveMQ Server
Step 4
Execute Consumer [mvn execjava -DexecmainClass=orgapacheactivemqbookch4Consumer
-Dexecargs=ssllocalhost61617 CSCO ORCL] =gt Gives Error
Note - To resolve this error we need to provide some basic system properties
javaxnetsslkeyStoremdashDefines which keystore the client should use
javaxnetsslkeyStorePasswordmdashDefines an appropriate password for the keystore
javaxnetssltrustStoremdashDefines an appropriate truststore the client should use
Step 4
Execute Following Command for Publisher
mvn -DjavaxnetsslkeyStore=$ACTIVEMQ_HOMEconfclientks -
DjavaxnetsslkeyStorePassword=password -
DjavaxnetssltrustStore=$ACTIVEMQ_HOMEconfclientts execjava -
DexecmainClass=orgapacheactivemqbookch4Publisher -Dexecargs=ssllocalhost61617 CSCO
ORCL
Step 5
Execute Following Command for Consumer
mvn -DjavaxnetsslkeyStore=$ACTIVEMQ_HOMEconfclientks -
DjavaxnetsslkeyStorePassword=password -
DjavaxnetssltrustStore=$ACTIVEMQ_HOMEconfclientts execjava
DexecmainClass=orgapacheactivemqbookch4Consumer -Dexecargs=ssllocalhost61617 CSCO
ORCL
It basically needs two types stored keys and certificates The first so called is keystore(brokerks) and the
another is truststore (brokerts)
Note - You can also enable and disable the SSL ciphers
ACTIVEMQ_HOMEconfactivemqxml
Add Following Lines of Code
lttransportConnectorsgt
lttransportConnector
name=ssl uri=ssllocalhost61617transportenabledCipherSuites=SSL_RSA_WITH_RC4_128_SHA
gt
lttransportConnectorsgt
Hypertext Transfer Protocol [HttpHttps]
Systems where firewalls are configured to allow basic services such as web access and email In those
scenarios ActiveMQ comes into existence
ActiveMQ implements the HTTP Transport connector which provides the xml formatted data to broker
using HTTP Protocol
Syntax HTTP HTTPS
httphostnameportkey=value
httpshostnameportkey=value
Example Add following code lines to execute this SSL example
Edit [confactivemqxml]
lttransportConnectorsgt
lttransportConnector name=tcp uri=tcplocalhost61616trace=truegt
lttransportConnector name=http uri=httplocalhost8080trace=true gt
lttransportConnectorsgt
Note- Basically there are two transports that are listening to port 8080 TCP transport and HTTP
Transport
ltdependencygt
ltgroupIdgtorgapacheactivemqltgroupIdgt
ltartifactIdgtactivemq-optionalltartifactIdgt
ltversiongt541ltversiongt
ltdependencygt
ActiveMQ Connectors
Understanding Connector URI
Itrsquos a compact string of characters that are used to refer a resource
Basically every URI has a following string resource ltschemegtltscheme-specific-partgt for ex
mailtoabcactivemqapacheorg
Where mailto ndash is scheme and Scheme-Specific-Part is the actual mail address
As we saw in previous examples that tcplocalhost61616trace=true ActiveMQ comes with the
concept of composite URI A composite URI automatically reconnects to another URI over failure of first
resource URI Ex static(tcphost161616tcphost261616)
HERE ABOVE STATIC IS lsquoSCHEMErsquo AND THERE ARE TWO PATHS
Note- White Space are not supported in composite URI
Transport Connectors
Transport connectors are used to send messages and receive messages fromto broker
Configuring Transport Connectors
Let us take that same portfolio example take a look at ActiveMQ demo configuration file
(confactivemq-demoxml)
lttransportConnectorsgt
lttransport-connector name=openwire uri=rdquotcplocalhost61616rdquogt
lttransportConnector name=ssl uri=ssllocalhost61617gt
lttransportConnector name=stomp uri=stomplocalhost61613gt
lttransportConnector name=xmpp uri=xmpplocalhost61222gt
lttransportConnectorsgt
Following code should be enough to get on transport connectors
ActiveMQConnectionFactory factory =
new ActiveMQConnectionFactory(tcplocalhost61616)
Connection connection = factorycreateConnection()
connectionstart()
Session session =
connectioncreateSession(false SessionAUTO_ACKNOWLEDGE)
Protocols
TCP [Transmission Control Protocol]
TCP has its own benefits of transferring data over peer to peer over years of long time we are relying on
TCP for successfully and securely sending data over Network
In TCP for sending messages in JMS we need to serialize messages in an suitable form ie They must be
serialized in and out as byte sequence to be sent over the wire protocol The default protocol used in
ActiveMQ is wire protocol
Syntax
Tcphostnameportkey=valueampkey=value
The following snippet of code needs to be added into the default configuration
lttransportConnectorsgt
lttransportConnector name=tcprdquo uri=tcplocalhost61616trace=truegt
lttransportConnectorsgt
mvn execjava -DexecmainClass=orgapacheactivemqbookch4Consumer -
Dexecargs=tcplocalhost61616 CSCO ORCL
Benefits of TCP
Efficiency
Since TCP uses open wire protocol for converting and receiving bytes over network It is very
efficient in terms of usage and performance
Reliability
Messages wonrsquot be lost over network
NIO [New IO Api Protocol]
New Input Output connector is not the replacement of traditional Java IO library It was an alternative
approach to network programming and access to some low-level IO operations of modern operating
systems
In all NIO is same as TCP the only difference is in its implementation TCP uses internally openwire that
makes it more secure and is implemented using transport API where as NIO connector is implemented
using NIO API
When there are so many clients wants to get connected to broker and the system may feel like
completely overloaded from clients at that moment NIO protocol can be used
Syntax
niohostnameportkey=value
Example [Add to the default configuration] ie confactivemqxml
lttransportConnectorsgt
lttransportConnector name=tcp uri=tcplocalhost61616trace=true gt
lttransportConnector name=nio uri=niolocalhost61618trace=true gt
lttransportConnectorsgt
Note - NIO connector must not set on the client side as it is server specific client needs to use TCP and
since server needs to maintain load and other issues we need to use NIO at server side
Letrsquos simply execute the example using following steps
Step 1
Goto confactivemqxml
Step 2
Add the Following lines in the lttransportconnectorsgt
lttransportConnector name=nio uri=niolocalhost61618trace=true gt
Step 3
Restart ActiveMQ Server
Step 4
Execute Publisher [mvn execjava -DexecmainClass=orgapacheactivemqbookch4Publisher
-Dexecargs=niolocalhost61618 CSCO ORCL]
Step 5
Execute Consumer [mvn execjava -DexecmainClass=orgapacheactivemqbookch4Consumer
-Dexecargs=tcplocalhost61616 CSCO ORCL]
Just look at this issue will help a lot in getting the beneath of
lsquohttpactivemq2283324n4nabblecomProblem-with-NIO-protocol-td3540710htmlrsquo
UDP [User Datagram Protocol]
UDP was designed basically for faster transmission of data over network Situations where the
transferring of data is more important than its reliability in such cases UDP is preferable [Voip Online
Gaming]
Syntax
udphostnameportkey=value
Example Add following code lines to execute this UDP example
Edit [confactivemqxml]
lttransportconnectorsgt
lttransportConnector name=udp uri=udplocalhost61618trace=true gt
lttransportconnectorsgt
Letrsquos simply execute the example using following steps
Step 1
Goto confactivemqxml
Step 2
Add the Following lines in the lttransportconnectorsgt
lttransportConnector name=udp uri=udplocalhost61618trace=true gt
Step 3
Restart ActiveMQ Server
Step 4
Execute Publisher [mvn execjava -DexecmainClass=orgapacheactivemqbookch4Publisher
-Dexecargs=udplocalhost61618 CSCO ORCL]
Step 5
Execute Consumer [mvn execjava -DexecmainClass=orgapacheactivemqbookch4Consumer
-Dexecargs=tcplocalhost61616 CSCO ORCL]
IT completely depends on the user which protocol needs to be used
SSL [Secure Socket Layer]
In situations where security is more concern that transmission SSL is a secure protocol need to be used
in such situations It internally uses the TCP so it covers all the basic TCP properties apart from it it
encrypts the data on TCP channel makes it more secure
It uses SSL transport connector that adds an SSL layer over TCP It provides an encrypted communication
over client and brokers
Syntax
sslhostnameportkey=value
Example Add following code lines to execute this SSL example
Edit [confactivemqxml]
lttransportConnectorsgt
lttransportConnector name=ssl uri=ssllocalhost61617trace=true gt
lttransportConnectorsgt
Here executing example covers some extra steps since we need to create certificates (keystores) for the
client
Step 1
Goto confactivemqxml
Step 2
Add the Following lines in the lttransportconnectorsgt
lttransportConnector name=ssl uri=ssllocalhost61617trace=true gt
Step 3
Restart ActiveMQ Server
Step 4
Execute Consumer [mvn execjava -DexecmainClass=orgapacheactivemqbookch4Consumer
-Dexecargs=ssllocalhost61617 CSCO ORCL] =gt Gives Error
Note - To resolve this error we need to provide some basic system properties
javaxnetsslkeyStoremdashDefines which keystore the client should use
javaxnetsslkeyStorePasswordmdashDefines an appropriate password for the keystore
javaxnetssltrustStoremdashDefines an appropriate truststore the client should use
Step 4
Execute Following Command for Publisher
mvn -DjavaxnetsslkeyStore=$ACTIVEMQ_HOMEconfclientks -
DjavaxnetsslkeyStorePassword=password -
DjavaxnetssltrustStore=$ACTIVEMQ_HOMEconfclientts execjava -
DexecmainClass=orgapacheactivemqbookch4Publisher -Dexecargs=ssllocalhost61617 CSCO
ORCL
Step 5
Execute Following Command for Consumer
mvn -DjavaxnetsslkeyStore=$ACTIVEMQ_HOMEconfclientks -
DjavaxnetsslkeyStorePassword=password -
DjavaxnetssltrustStore=$ACTIVEMQ_HOMEconfclientts execjava
DexecmainClass=orgapacheactivemqbookch4Consumer -Dexecargs=ssllocalhost61617 CSCO
ORCL
It basically needs two types stored keys and certificates The first so called is keystore(brokerks) and the
another is truststore (brokerts)
Note - You can also enable and disable the SSL ciphers
ACTIVEMQ_HOMEconfactivemqxml
Add Following Lines of Code
lttransportConnectorsgt
lttransportConnector
name=ssl uri=ssllocalhost61617transportenabledCipherSuites=SSL_RSA_WITH_RC4_128_SHA
gt
lttransportConnectorsgt
Hypertext Transfer Protocol [HttpHttps]
Systems where firewalls are configured to allow basic services such as web access and email In those
scenarios ActiveMQ comes into existence
ActiveMQ implements the HTTP Transport connector which provides the xml formatted data to broker
using HTTP Protocol
Syntax HTTP HTTPS
httphostnameportkey=value
httpshostnameportkey=value
Example Add following code lines to execute this SSL example
Edit [confactivemqxml]
lttransportConnectorsgt
lttransportConnector name=tcp uri=tcplocalhost61616trace=truegt
lttransportConnector name=http uri=httplocalhost8080trace=true gt
lttransportConnectorsgt
Note- Basically there are two transports that are listening to port 8080 TCP transport and HTTP
Transport
ltdependencygt
ltgroupIdgtorgapacheactivemqltgroupIdgt
ltartifactIdgtactivemq-optionalltartifactIdgt
ltversiongt541ltversiongt
ltdependencygt
Connection connection = factorycreateConnection()
connectionstart()
Session session =
connectioncreateSession(false SessionAUTO_ACKNOWLEDGE)
Protocols
TCP [Transmission Control Protocol]
TCP has its own benefits of transferring data over peer to peer over years of long time we are relying on
TCP for successfully and securely sending data over Network
In TCP for sending messages in JMS we need to serialize messages in an suitable form ie They must be
serialized in and out as byte sequence to be sent over the wire protocol The default protocol used in
ActiveMQ is wire protocol
Syntax
Tcphostnameportkey=valueampkey=value
The following snippet of code needs to be added into the default configuration
lttransportConnectorsgt
lttransportConnector name=tcprdquo uri=tcplocalhost61616trace=truegt
lttransportConnectorsgt
mvn execjava -DexecmainClass=orgapacheactivemqbookch4Consumer -
Dexecargs=tcplocalhost61616 CSCO ORCL
Benefits of TCP
Efficiency
Since TCP uses open wire protocol for converting and receiving bytes over network It is very
efficient in terms of usage and performance
Reliability
Messages wonrsquot be lost over network
NIO [New IO Api Protocol]
New Input Output connector is not the replacement of traditional Java IO library It was an alternative
approach to network programming and access to some low-level IO operations of modern operating
systems
In all NIO is same as TCP the only difference is in its implementation TCP uses internally openwire that
makes it more secure and is implemented using transport API where as NIO connector is implemented
using NIO API
When there are so many clients wants to get connected to broker and the system may feel like
completely overloaded from clients at that moment NIO protocol can be used
Syntax
niohostnameportkey=value
Example [Add to the default configuration] ie confactivemqxml
lttransportConnectorsgt
lttransportConnector name=tcp uri=tcplocalhost61616trace=true gt
lttransportConnector name=nio uri=niolocalhost61618trace=true gt
lttransportConnectorsgt
Note - NIO connector must not set on the client side as it is server specific client needs to use TCP and
since server needs to maintain load and other issues we need to use NIO at server side
Letrsquos simply execute the example using following steps
Step 1
Goto confactivemqxml
Step 2
Add the Following lines in the lttransportconnectorsgt
lttransportConnector name=nio uri=niolocalhost61618trace=true gt
Step 3
Restart ActiveMQ Server
Step 4
Execute Publisher [mvn execjava -DexecmainClass=orgapacheactivemqbookch4Publisher
-Dexecargs=niolocalhost61618 CSCO ORCL]
Step 5
Execute Consumer [mvn execjava -DexecmainClass=orgapacheactivemqbookch4Consumer
-Dexecargs=tcplocalhost61616 CSCO ORCL]
Just look at this issue will help a lot in getting the beneath of
lsquohttpactivemq2283324n4nabblecomProblem-with-NIO-protocol-td3540710htmlrsquo
UDP [User Datagram Protocol]
UDP was designed basically for faster transmission of data over network Situations where the
transferring of data is more important than its reliability in such cases UDP is preferable [Voip Online
Gaming]
Syntax
udphostnameportkey=value
Example Add following code lines to execute this UDP example
Edit [confactivemqxml]
lttransportconnectorsgt
lttransportConnector name=udp uri=udplocalhost61618trace=true gt
lttransportconnectorsgt
Letrsquos simply execute the example using following steps
Step 1
Goto confactivemqxml
Step 2
Add the Following lines in the lttransportconnectorsgt
lttransportConnector name=udp uri=udplocalhost61618trace=true gt
Step 3
Restart ActiveMQ Server
Step 4
Execute Publisher [mvn execjava -DexecmainClass=orgapacheactivemqbookch4Publisher
-Dexecargs=udplocalhost61618 CSCO ORCL]
Step 5
Execute Consumer [mvn execjava -DexecmainClass=orgapacheactivemqbookch4Consumer
-Dexecargs=tcplocalhost61616 CSCO ORCL]
IT completely depends on the user which protocol needs to be used
SSL [Secure Socket Layer]
In situations where security is more concern that transmission SSL is a secure protocol need to be used
in such situations It internally uses the TCP so it covers all the basic TCP properties apart from it it
encrypts the data on TCP channel makes it more secure
It uses SSL transport connector that adds an SSL layer over TCP It provides an encrypted communication
over client and brokers
Syntax
sslhostnameportkey=value
Example Add following code lines to execute this SSL example
Edit [confactivemqxml]
lttransportConnectorsgt
lttransportConnector name=ssl uri=ssllocalhost61617trace=true gt
lttransportConnectorsgt
Here executing example covers some extra steps since we need to create certificates (keystores) for the
client
Step 1
Goto confactivemqxml
Step 2
Add the Following lines in the lttransportconnectorsgt
lttransportConnector name=ssl uri=ssllocalhost61617trace=true gt
Step 3
Restart ActiveMQ Server
Step 4
Execute Consumer [mvn execjava -DexecmainClass=orgapacheactivemqbookch4Consumer
-Dexecargs=ssllocalhost61617 CSCO ORCL] =gt Gives Error
Note - To resolve this error we need to provide some basic system properties
javaxnetsslkeyStoremdashDefines which keystore the client should use
javaxnetsslkeyStorePasswordmdashDefines an appropriate password for the keystore
javaxnetssltrustStoremdashDefines an appropriate truststore the client should use
Step 4
Execute Following Command for Publisher
mvn -DjavaxnetsslkeyStore=$ACTIVEMQ_HOMEconfclientks -
DjavaxnetsslkeyStorePassword=password -
DjavaxnetssltrustStore=$ACTIVEMQ_HOMEconfclientts execjava -
DexecmainClass=orgapacheactivemqbookch4Publisher -Dexecargs=ssllocalhost61617 CSCO
ORCL
Step 5
Execute Following Command for Consumer
mvn -DjavaxnetsslkeyStore=$ACTIVEMQ_HOMEconfclientks -
DjavaxnetsslkeyStorePassword=password -
DjavaxnetssltrustStore=$ACTIVEMQ_HOMEconfclientts execjava
DexecmainClass=orgapacheactivemqbookch4Consumer -Dexecargs=ssllocalhost61617 CSCO
ORCL
It basically needs two types stored keys and certificates The first so called is keystore(brokerks) and the
another is truststore (brokerts)
Note - You can also enable and disable the SSL ciphers
ACTIVEMQ_HOMEconfactivemqxml
Add Following Lines of Code
lttransportConnectorsgt
lttransportConnector
name=ssl uri=ssllocalhost61617transportenabledCipherSuites=SSL_RSA_WITH_RC4_128_SHA
gt
lttransportConnectorsgt
Hypertext Transfer Protocol [HttpHttps]
Systems where firewalls are configured to allow basic services such as web access and email In those
scenarios ActiveMQ comes into existence
ActiveMQ implements the HTTP Transport connector which provides the xml formatted data to broker
using HTTP Protocol
Syntax HTTP HTTPS
httphostnameportkey=value
httpshostnameportkey=value
Example Add following code lines to execute this SSL example
Edit [confactivemqxml]
lttransportConnectorsgt
lttransportConnector name=tcp uri=tcplocalhost61616trace=truegt
lttransportConnector name=http uri=httplocalhost8080trace=true gt
lttransportConnectorsgt
Note- Basically there are two transports that are listening to port 8080 TCP transport and HTTP
Transport
ltdependencygt
ltgroupIdgtorgapacheactivemqltgroupIdgt
ltartifactIdgtactivemq-optionalltartifactIdgt
ltversiongt541ltversiongt
ltdependencygt
Messages wonrsquot be lost over network
NIO [New IO Api Protocol]
New Input Output connector is not the replacement of traditional Java IO library It was an alternative
approach to network programming and access to some low-level IO operations of modern operating
systems
In all NIO is same as TCP the only difference is in its implementation TCP uses internally openwire that
makes it more secure and is implemented using transport API where as NIO connector is implemented
using NIO API
When there are so many clients wants to get connected to broker and the system may feel like
completely overloaded from clients at that moment NIO protocol can be used
Syntax
niohostnameportkey=value
Example [Add to the default configuration] ie confactivemqxml
lttransportConnectorsgt
lttransportConnector name=tcp uri=tcplocalhost61616trace=true gt
lttransportConnector name=nio uri=niolocalhost61618trace=true gt
lttransportConnectorsgt
Note - NIO connector must not set on the client side as it is server specific client needs to use TCP and
since server needs to maintain load and other issues we need to use NIO at server side
Letrsquos simply execute the example using following steps
Step 1
Goto confactivemqxml
Step 2
Add the Following lines in the lttransportconnectorsgt
lttransportConnector name=nio uri=niolocalhost61618trace=true gt
Step 3
Restart ActiveMQ Server
Step 4
Execute Publisher [mvn execjava -DexecmainClass=orgapacheactivemqbookch4Publisher
-Dexecargs=niolocalhost61618 CSCO ORCL]
Step 5
Execute Consumer [mvn execjava -DexecmainClass=orgapacheactivemqbookch4Consumer
-Dexecargs=tcplocalhost61616 CSCO ORCL]
Just look at this issue will help a lot in getting the beneath of
lsquohttpactivemq2283324n4nabblecomProblem-with-NIO-protocol-td3540710htmlrsquo
UDP [User Datagram Protocol]
UDP was designed basically for faster transmission of data over network Situations where the
transferring of data is more important than its reliability in such cases UDP is preferable [Voip Online
Gaming]
Syntax
udphostnameportkey=value
Example Add following code lines to execute this UDP example
Edit [confactivemqxml]
lttransportconnectorsgt
lttransportConnector name=udp uri=udplocalhost61618trace=true gt
lttransportconnectorsgt
Letrsquos simply execute the example using following steps
Step 1
Goto confactivemqxml
Step 2
Add the Following lines in the lttransportconnectorsgt
lttransportConnector name=udp uri=udplocalhost61618trace=true gt
Step 3
Restart ActiveMQ Server
Step 4
Execute Publisher [mvn execjava -DexecmainClass=orgapacheactivemqbookch4Publisher
-Dexecargs=udplocalhost61618 CSCO ORCL]
Step 5
Execute Consumer [mvn execjava -DexecmainClass=orgapacheactivemqbookch4Consumer
-Dexecargs=tcplocalhost61616 CSCO ORCL]
IT completely depends on the user which protocol needs to be used
SSL [Secure Socket Layer]
In situations where security is more concern that transmission SSL is a secure protocol need to be used
in such situations It internally uses the TCP so it covers all the basic TCP properties apart from it it
encrypts the data on TCP channel makes it more secure
It uses SSL transport connector that adds an SSL layer over TCP It provides an encrypted communication
over client and brokers
Syntax
sslhostnameportkey=value
Example Add following code lines to execute this SSL example
Edit [confactivemqxml]
lttransportConnectorsgt
lttransportConnector name=ssl uri=ssllocalhost61617trace=true gt
lttransportConnectorsgt
Here executing example covers some extra steps since we need to create certificates (keystores) for the
client
Step 1
Goto confactivemqxml
Step 2
Add the Following lines in the lttransportconnectorsgt
lttransportConnector name=ssl uri=ssllocalhost61617trace=true gt
Step 3
Restart ActiveMQ Server
Step 4
Execute Consumer [mvn execjava -DexecmainClass=orgapacheactivemqbookch4Consumer
-Dexecargs=ssllocalhost61617 CSCO ORCL] =gt Gives Error
Note - To resolve this error we need to provide some basic system properties
javaxnetsslkeyStoremdashDefines which keystore the client should use
javaxnetsslkeyStorePasswordmdashDefines an appropriate password for the keystore
javaxnetssltrustStoremdashDefines an appropriate truststore the client should use
Step 4
Execute Following Command for Publisher
mvn -DjavaxnetsslkeyStore=$ACTIVEMQ_HOMEconfclientks -
DjavaxnetsslkeyStorePassword=password -
DjavaxnetssltrustStore=$ACTIVEMQ_HOMEconfclientts execjava -
DexecmainClass=orgapacheactivemqbookch4Publisher -Dexecargs=ssllocalhost61617 CSCO
ORCL
Step 5
Execute Following Command for Consumer
mvn -DjavaxnetsslkeyStore=$ACTIVEMQ_HOMEconfclientks -
DjavaxnetsslkeyStorePassword=password -
DjavaxnetssltrustStore=$ACTIVEMQ_HOMEconfclientts execjava
DexecmainClass=orgapacheactivemqbookch4Consumer -Dexecargs=ssllocalhost61617 CSCO
ORCL
It basically needs two types stored keys and certificates The first so called is keystore(brokerks) and the
another is truststore (brokerts)
Note - You can also enable and disable the SSL ciphers
ACTIVEMQ_HOMEconfactivemqxml
Add Following Lines of Code
lttransportConnectorsgt
lttransportConnector
name=ssl uri=ssllocalhost61617transportenabledCipherSuites=SSL_RSA_WITH_RC4_128_SHA
gt
lttransportConnectorsgt
Hypertext Transfer Protocol [HttpHttps]
Systems where firewalls are configured to allow basic services such as web access and email In those
scenarios ActiveMQ comes into existence
ActiveMQ implements the HTTP Transport connector which provides the xml formatted data to broker
using HTTP Protocol
Syntax HTTP HTTPS
httphostnameportkey=value
httpshostnameportkey=value
Example Add following code lines to execute this SSL example
Edit [confactivemqxml]
lttransportConnectorsgt
lttransportConnector name=tcp uri=tcplocalhost61616trace=truegt
lttransportConnector name=http uri=httplocalhost8080trace=true gt
lttransportConnectorsgt
Note- Basically there are two transports that are listening to port 8080 TCP transport and HTTP
Transport
ltdependencygt
ltgroupIdgtorgapacheactivemqltgroupIdgt
ltartifactIdgtactivemq-optionalltartifactIdgt
ltversiongt541ltversiongt
ltdependencygt
Step 3
Restart ActiveMQ Server
Step 4
Execute Publisher [mvn execjava -DexecmainClass=orgapacheactivemqbookch4Publisher
-Dexecargs=niolocalhost61618 CSCO ORCL]
Step 5
Execute Consumer [mvn execjava -DexecmainClass=orgapacheactivemqbookch4Consumer
-Dexecargs=tcplocalhost61616 CSCO ORCL]
Just look at this issue will help a lot in getting the beneath of
lsquohttpactivemq2283324n4nabblecomProblem-with-NIO-protocol-td3540710htmlrsquo
UDP [User Datagram Protocol]
UDP was designed basically for faster transmission of data over network Situations where the
transferring of data is more important than its reliability in such cases UDP is preferable [Voip Online
Gaming]
Syntax
udphostnameportkey=value
Example Add following code lines to execute this UDP example
Edit [confactivemqxml]
lttransportconnectorsgt
lttransportConnector name=udp uri=udplocalhost61618trace=true gt
lttransportconnectorsgt
Letrsquos simply execute the example using following steps
Step 1
Goto confactivemqxml
Step 2
Add the Following lines in the lttransportconnectorsgt
lttransportConnector name=udp uri=udplocalhost61618trace=true gt
Step 3
Restart ActiveMQ Server
Step 4
Execute Publisher [mvn execjava -DexecmainClass=orgapacheactivemqbookch4Publisher
-Dexecargs=udplocalhost61618 CSCO ORCL]
Step 5
Execute Consumer [mvn execjava -DexecmainClass=orgapacheactivemqbookch4Consumer
-Dexecargs=tcplocalhost61616 CSCO ORCL]
IT completely depends on the user which protocol needs to be used
SSL [Secure Socket Layer]
In situations where security is more concern that transmission SSL is a secure protocol need to be used
in such situations It internally uses the TCP so it covers all the basic TCP properties apart from it it
encrypts the data on TCP channel makes it more secure
It uses SSL transport connector that adds an SSL layer over TCP It provides an encrypted communication
over client and brokers
Syntax
sslhostnameportkey=value
Example Add following code lines to execute this SSL example
Edit [confactivemqxml]
lttransportConnectorsgt
lttransportConnector name=ssl uri=ssllocalhost61617trace=true gt
lttransportConnectorsgt
Here executing example covers some extra steps since we need to create certificates (keystores) for the
client
Step 1
Goto confactivemqxml
Step 2
Add the Following lines in the lttransportconnectorsgt
lttransportConnector name=ssl uri=ssllocalhost61617trace=true gt
Step 3
Restart ActiveMQ Server
Step 4
Execute Consumer [mvn execjava -DexecmainClass=orgapacheactivemqbookch4Consumer
-Dexecargs=ssllocalhost61617 CSCO ORCL] =gt Gives Error
Note - To resolve this error we need to provide some basic system properties
javaxnetsslkeyStoremdashDefines which keystore the client should use
javaxnetsslkeyStorePasswordmdashDefines an appropriate password for the keystore
javaxnetssltrustStoremdashDefines an appropriate truststore the client should use
Step 4
Execute Following Command for Publisher
mvn -DjavaxnetsslkeyStore=$ACTIVEMQ_HOMEconfclientks -
DjavaxnetsslkeyStorePassword=password -
DjavaxnetssltrustStore=$ACTIVEMQ_HOMEconfclientts execjava -
DexecmainClass=orgapacheactivemqbookch4Publisher -Dexecargs=ssllocalhost61617 CSCO
ORCL
Step 5
Execute Following Command for Consumer
mvn -DjavaxnetsslkeyStore=$ACTIVEMQ_HOMEconfclientks -
DjavaxnetsslkeyStorePassword=password -
DjavaxnetssltrustStore=$ACTIVEMQ_HOMEconfclientts execjava
DexecmainClass=orgapacheactivemqbookch4Consumer -Dexecargs=ssllocalhost61617 CSCO
ORCL
It basically needs two types stored keys and certificates The first so called is keystore(brokerks) and the
another is truststore (brokerts)
Note - You can also enable and disable the SSL ciphers
ACTIVEMQ_HOMEconfactivemqxml
Add Following Lines of Code
lttransportConnectorsgt
lttransportConnector
name=ssl uri=ssllocalhost61617transportenabledCipherSuites=SSL_RSA_WITH_RC4_128_SHA
gt
lttransportConnectorsgt
Hypertext Transfer Protocol [HttpHttps]
Systems where firewalls are configured to allow basic services such as web access and email In those
scenarios ActiveMQ comes into existence
ActiveMQ implements the HTTP Transport connector which provides the xml formatted data to broker
using HTTP Protocol
Syntax HTTP HTTPS
httphostnameportkey=value
httpshostnameportkey=value
Example Add following code lines to execute this SSL example
Edit [confactivemqxml]
lttransportConnectorsgt
lttransportConnector name=tcp uri=tcplocalhost61616trace=truegt
lttransportConnector name=http uri=httplocalhost8080trace=true gt
lttransportConnectorsgt
Note- Basically there are two transports that are listening to port 8080 TCP transport and HTTP
Transport
ltdependencygt
ltgroupIdgtorgapacheactivemqltgroupIdgt
ltartifactIdgtactivemq-optionalltartifactIdgt
ltversiongt541ltversiongt
ltdependencygt
Goto confactivemqxml
Step 2
Add the Following lines in the lttransportconnectorsgt
lttransportConnector name=udp uri=udplocalhost61618trace=true gt
Step 3
Restart ActiveMQ Server
Step 4
Execute Publisher [mvn execjava -DexecmainClass=orgapacheactivemqbookch4Publisher
-Dexecargs=udplocalhost61618 CSCO ORCL]
Step 5
Execute Consumer [mvn execjava -DexecmainClass=orgapacheactivemqbookch4Consumer
-Dexecargs=tcplocalhost61616 CSCO ORCL]
IT completely depends on the user which protocol needs to be used
SSL [Secure Socket Layer]
In situations where security is more concern that transmission SSL is a secure protocol need to be used
in such situations It internally uses the TCP so it covers all the basic TCP properties apart from it it
encrypts the data on TCP channel makes it more secure
It uses SSL transport connector that adds an SSL layer over TCP It provides an encrypted communication
over client and brokers
Syntax
sslhostnameportkey=value
Example Add following code lines to execute this SSL example
Edit [confactivemqxml]
lttransportConnectorsgt
lttransportConnector name=ssl uri=ssllocalhost61617trace=true gt
lttransportConnectorsgt
Here executing example covers some extra steps since we need to create certificates (keystores) for the
client
Step 1
Goto confactivemqxml
Step 2
Add the Following lines in the lttransportconnectorsgt
lttransportConnector name=ssl uri=ssllocalhost61617trace=true gt
Step 3
Restart ActiveMQ Server
Step 4
Execute Consumer [mvn execjava -DexecmainClass=orgapacheactivemqbookch4Consumer
-Dexecargs=ssllocalhost61617 CSCO ORCL] =gt Gives Error
Note - To resolve this error we need to provide some basic system properties
javaxnetsslkeyStoremdashDefines which keystore the client should use
javaxnetsslkeyStorePasswordmdashDefines an appropriate password for the keystore
javaxnetssltrustStoremdashDefines an appropriate truststore the client should use
Step 4
Execute Following Command for Publisher
mvn -DjavaxnetsslkeyStore=$ACTIVEMQ_HOMEconfclientks -
DjavaxnetsslkeyStorePassword=password -
DjavaxnetssltrustStore=$ACTIVEMQ_HOMEconfclientts execjava -
DexecmainClass=orgapacheactivemqbookch4Publisher -Dexecargs=ssllocalhost61617 CSCO
ORCL
Step 5
Execute Following Command for Consumer
mvn -DjavaxnetsslkeyStore=$ACTIVEMQ_HOMEconfclientks -
DjavaxnetsslkeyStorePassword=password -
DjavaxnetssltrustStore=$ACTIVEMQ_HOMEconfclientts execjava
DexecmainClass=orgapacheactivemqbookch4Consumer -Dexecargs=ssllocalhost61617 CSCO
ORCL
It basically needs two types stored keys and certificates The first so called is keystore(brokerks) and the
another is truststore (brokerts)
Note - You can also enable and disable the SSL ciphers
ACTIVEMQ_HOMEconfactivemqxml
Add Following Lines of Code
lttransportConnectorsgt
lttransportConnector
name=ssl uri=ssllocalhost61617transportenabledCipherSuites=SSL_RSA_WITH_RC4_128_SHA
gt
lttransportConnectorsgt
Hypertext Transfer Protocol [HttpHttps]
Systems where firewalls are configured to allow basic services such as web access and email In those
scenarios ActiveMQ comes into existence
ActiveMQ implements the HTTP Transport connector which provides the xml formatted data to broker
using HTTP Protocol
Syntax HTTP HTTPS
httphostnameportkey=value
httpshostnameportkey=value
Example Add following code lines to execute this SSL example
Edit [confactivemqxml]
lttransportConnectorsgt
lttransportConnector name=tcp uri=tcplocalhost61616trace=truegt
lttransportConnector name=http uri=httplocalhost8080trace=true gt
lttransportConnectorsgt
Note- Basically there are two transports that are listening to port 8080 TCP transport and HTTP
Transport
ltdependencygt
ltgroupIdgtorgapacheactivemqltgroupIdgt
ltartifactIdgtactivemq-optionalltartifactIdgt
ltversiongt541ltversiongt
ltdependencygt
lttransportConnectorsgt
lttransportConnector name=ssl uri=ssllocalhost61617trace=true gt
lttransportConnectorsgt
Here executing example covers some extra steps since we need to create certificates (keystores) for the
client
Step 1
Goto confactivemqxml
Step 2
Add the Following lines in the lttransportconnectorsgt
lttransportConnector name=ssl uri=ssllocalhost61617trace=true gt
Step 3
Restart ActiveMQ Server
Step 4
Execute Consumer [mvn execjava -DexecmainClass=orgapacheactivemqbookch4Consumer
-Dexecargs=ssllocalhost61617 CSCO ORCL] =gt Gives Error
Note - To resolve this error we need to provide some basic system properties
javaxnetsslkeyStoremdashDefines which keystore the client should use
javaxnetsslkeyStorePasswordmdashDefines an appropriate password for the keystore
javaxnetssltrustStoremdashDefines an appropriate truststore the client should use
Step 4
Execute Following Command for Publisher
mvn -DjavaxnetsslkeyStore=$ACTIVEMQ_HOMEconfclientks -
DjavaxnetsslkeyStorePassword=password -
DjavaxnetssltrustStore=$ACTIVEMQ_HOMEconfclientts execjava -
DexecmainClass=orgapacheactivemqbookch4Publisher -Dexecargs=ssllocalhost61617 CSCO
ORCL
Step 5
Execute Following Command for Consumer
mvn -DjavaxnetsslkeyStore=$ACTIVEMQ_HOMEconfclientks -
DjavaxnetsslkeyStorePassword=password -
DjavaxnetssltrustStore=$ACTIVEMQ_HOMEconfclientts execjava
DexecmainClass=orgapacheactivemqbookch4Consumer -Dexecargs=ssllocalhost61617 CSCO
ORCL
It basically needs two types stored keys and certificates The first so called is keystore(brokerks) and the
another is truststore (brokerts)
Note - You can also enable and disable the SSL ciphers
ACTIVEMQ_HOMEconfactivemqxml
Add Following Lines of Code
lttransportConnectorsgt
lttransportConnector
name=ssl uri=ssllocalhost61617transportenabledCipherSuites=SSL_RSA_WITH_RC4_128_SHA
gt
lttransportConnectorsgt
Hypertext Transfer Protocol [HttpHttps]
Systems where firewalls are configured to allow basic services such as web access and email In those
scenarios ActiveMQ comes into existence
ActiveMQ implements the HTTP Transport connector which provides the xml formatted data to broker
using HTTP Protocol
Syntax HTTP HTTPS
httphostnameportkey=value
httpshostnameportkey=value
Example Add following code lines to execute this SSL example
Edit [confactivemqxml]
lttransportConnectorsgt
lttransportConnector name=tcp uri=tcplocalhost61616trace=truegt
lttransportConnector name=http uri=httplocalhost8080trace=true gt
lttransportConnectorsgt
Note- Basically there are two transports that are listening to port 8080 TCP transport and HTTP
Transport
ltdependencygt
ltgroupIdgtorgapacheactivemqltgroupIdgt
ltartifactIdgtactivemq-optionalltartifactIdgt
ltversiongt541ltversiongt
ltdependencygt
Step 5
Execute Following Command for Consumer
mvn -DjavaxnetsslkeyStore=$ACTIVEMQ_HOMEconfclientks -
DjavaxnetsslkeyStorePassword=password -
DjavaxnetssltrustStore=$ACTIVEMQ_HOMEconfclientts execjava
DexecmainClass=orgapacheactivemqbookch4Consumer -Dexecargs=ssllocalhost61617 CSCO
ORCL
It basically needs two types stored keys and certificates The first so called is keystore(brokerks) and the
another is truststore (brokerts)
Note - You can also enable and disable the SSL ciphers
ACTIVEMQ_HOMEconfactivemqxml
Add Following Lines of Code
lttransportConnectorsgt
lttransportConnector
name=ssl uri=ssllocalhost61617transportenabledCipherSuites=SSL_RSA_WITH_RC4_128_SHA
gt
lttransportConnectorsgt
Hypertext Transfer Protocol [HttpHttps]
Systems where firewalls are configured to allow basic services such as web access and email In those
scenarios ActiveMQ comes into existence
ActiveMQ implements the HTTP Transport connector which provides the xml formatted data to broker
using HTTP Protocol
Syntax HTTP HTTPS
httphostnameportkey=value
httpshostnameportkey=value
Example Add following code lines to execute this SSL example
Edit [confactivemqxml]
lttransportConnectorsgt
lttransportConnector name=tcp uri=tcplocalhost61616trace=truegt
lttransportConnector name=http uri=httplocalhost8080trace=true gt
lttransportConnectorsgt
Note- Basically there are two transports that are listening to port 8080 TCP transport and HTTP
Transport
ltdependencygt
ltgroupIdgtorgapacheactivemqltgroupIdgt
ltartifactIdgtactivemq-optionalltartifactIdgt
ltversiongt541ltversiongt
ltdependencygt
httpshostnameportkey=value
Example Add following code lines to execute this SSL example
Edit [confactivemqxml]
lttransportConnectorsgt
lttransportConnector name=tcp uri=tcplocalhost61616trace=truegt
lttransportConnector name=http uri=httplocalhost8080trace=true gt
lttransportConnectorsgt
Note- Basically there are two transports that are listening to port 8080 TCP transport and HTTP
Transport
ltdependencygt
ltgroupIdgtorgapacheactivemqltgroupIdgt
ltartifactIdgtactivemq-optionalltartifactIdgt
ltversiongt541ltversiongt
ltdependencygt