You are on page 1of 29

Professional Open Source™

JBossMQ
Messaging, JMS, JBossMQ Architecture, Advanced Configuration and Tuning

© JBoss, Inc. 2003-2005. 8/2/2005 1

Topics
Professional Open Source™

Messaging and JMS


– The Need for Messaging
– JMS API and Programming Models
– JMS and Reliability

JBossMQ
– Architectural Overview
– The Inflow of a message through JBossMQ
– JBossMQ Components
– JBossMQ Configuration
– JBossMQ Fine Tuning

High Availability JBossMQ

JMS and JBossMQ Anti-Patterns


– How NOT to use JBossMQ

© JBoss, Inc. 2003-2005. 2

1
The Need for Messaging
Professional Open Source™

The integration of heterogeneous applications can be done via

File Transfer
– One application writes to a file and another application reads from the file.
The applications need to agree on location, format and timing.
Shared Database
– Multiple applications share the same database schema and a single
physical database.
Remote Procedure Invocation
– One application exposes functionality that can be accessed remotely and
synchronously.
Messaging
– One application sends a message to a provider, another application
asynchronously reads the message from the provider at a later time.
Web Services

© JBoss, Inc. 2003-2005. 3

Messaging Pros
Professional Open Source™

Efficient use of resources


– Invocations are asynchronous, no thread blocks waiting for the other party
to answer.
– Fire-and-forget strategy.
Reduced interface dependencies between components
– The components do not need to know the RPC interfaces of their
counterparts.
Functional decoupling
– Allow an application to run without all components being available at the
same time.
– The messaging system stores the messages in transit.
Reliable communication
– The messaging system provides guaranteed delivery, once and only
once.
Support for multiple senders and receivers
– Allow for n-ary communication.

© JBoss, Inc. 2003-2005. 4

2
Messaging Cons
Professional Open Source™

More complicated programming model


– More verbose API than RPC’s.
– More configuration issues to deal with.

© JBoss, Inc. 2003-2005. 5

Java Message Service


Professional Open Source™

The Java API that allows applications to create, send, receive and
read messages

Defines a common set of interfaces and the associated semantics

Integral part of J2EE

Supports two messaging domains


– Point-to-Point (Queues)
– Publish/Subscribe (Topics)

… and a cross between these domains


– Topics with Durable Subscriptions

© JBoss, Inc. 2003-2005. 6

3
JMS Messaging Domains
Professional Open Source™

Message
Sender m1
Sender m7
m7 Receiver
Receiver
se
nd Queue
Queue rec
eiv
e

Sender
Sender m6 m5 m4 m3
Receiver
Receiver
m2
re
ce
Sender
Sender iv
e Receiver
Receiver

Message m1
Sender
Sender m1 Receiver
Receiver
e iv e
se rec
nd Topic m1
Topic
Sender
Sender Receiver
Receiver
receive

m1
Sender
Sender re
ce
iv Receiver
Receiver
e

© JBoss, Inc. 2003-2005. 7

The JMS API


Professional Open Source™

QueueConnectionFactory
QueueConnectionFactory ConnectionFactory
ConnectionFactory TopicConnectionFactory
TopicConnectionFactory

creates creates creates

QueueConnection
QueueConnection Connection
Connection TopicConnection
TopicConnection

creates creates creates

QueueSession
QueueSession Session
Session TopicSession
TopicSession

creates creates creates creates creates creates

QueueSender
QueueSender QueueReceiver
QueueReceiver MessageProducer
MessageProducer MessageConsumer
MessageConsumer TopicPublisher
TopicPublisher TopicSubscriber
TopicSubscriber

creates

Message
Message

Queue
Queue Destination
Destination Topic
Topic

© JBoss, Inc. 2003-2005. 8

4
Reliability and JMS
Professional Open Source™

The Acknowledgement Option


– Two different acknowledgment sequences: the JMS provider
acknowledges reception , the receiver acknowledges delivery.
– AUTO_ACKNOWLEDGE, CLIENT_ACKNOWLEDGE, DUPS_OK_ACKNOWLEDGE
The Delivery Mode
– Defined on a per-message basis.
– PERSISTENT, NON_PERSISTENT
The Destination Type
– Queues: the message is always delivered.
– Topics: the subscribers that are not connected may lose messages.
– Topics with Durable Subscriptions: a combination between PtoP and
Pub/Sub.
Transactional Behavior
– A session can be transacted or not.

© JBoss, Inc. 2003-2005. 9

JBossMQ Features
Professional Open Source™

JBoss 4.x supports the JMS1.1 version of the specifications


JBoss 3.2.x supports the JMS1.0.2b version of the specifications

JBossMQ Features
– Fire-and-forget for asynchronous delivery
– Guaranteed Delivery using persistent messages and durable
subscriptions
– Dead Letter Queue (DLQ)
– Pluggable Invocation Layers to support different transport protocols
(TCP/IP, HTTP, in-memory invocations)
– Pluggable Security
– Pluggable Persistence
– JTA XA integration used by JBoss’ JMS resource adapter
– High Availability in a clustered environment

© JBoss, Inc. 2003-2005. 10

5
JBossMQ – An Architectural Overview
Professional Open Source™

ConnectionFactory
ConnectionFactory HTTP
HTTPILIL
Service
Service

JMSQueue

ServerSecurityInterceptor
JMSQueue

ServerSecurityInterceptor
Interceptor
Producer

TracingInterceptor
Producer Unified Invocation Layer
…..
UIL2 JMSDestination
JMSDestination MDB
MDB
Session
Session Connection
Connection UIL2
Invoker Manager
Manager Container
Container
Service
Service Invoker JMSTopic
JMSTopic

Tracing
Consumer
Consumer
JMSTopic
JMSTopic

JVM
JVMILIL
Service
Service

Remote Client VM
Security
Security State
State Message
Message
Manager
Manager Manager
Manager Cache
Cache

Persistence
Persistence
JaasSecurityManager
JaasSecurityManager Manager
Manager

JBossMQ VM
© JBoss, Inc. 2003-2005. 11

The inflow of a message through JBossMQ


Professional Open Source™

We will describe in detail JBossMQ architectural elements, by


following a JMS message sent by a remote client to a MDB that
subscribed to a topic.

During the walkthrough, we will insist on …

© JBoss, Inc. 2003-2005. 12

6
The inflow of a message through JBossMQ
Professional Open Source™

1. Sending
the message
on the client
side

ConnectionFactory
ConnectionFactory HTTP
HTTPILIL
Service
Service

JMSQueue

ServerSecurityInterceptor
JMSQueue

ServerSecurityInterceptor
Interceptor
Producer

TracingInterceptor
Producer Unified Invocation Layer
…..
UIL2 JMSDestination
JMSDestination MDB
MDB
Session
Session Connection
Connection UIL2
Invoker Manager
Manager Container
Container
Service
Service Invoker JMSTopic
JMSTopic

Tracing
Consumer
Consumer
JMSTopic
JMSTopic

JVM
JVMILIL
Service
Service

Remote Client VM
Security
Security State
State Message
Message
Manager
Manager Manager
Manager Cache
Cache

Persistence
Persistence
JaasSecurityManager
JaasSecurityManager Manager
Manager

JBossMQ VM
© JBoss, Inc. 2003-2005. 13

The inflow of a message through JBossMQ


Professional Open Source™
2. The ConnectionFactory.
1. Sending - How does it get bound in
the message JNDI?
on the client
side

ConnectionFactory
ConnectionFactory HTTP
HTTPILIL
Service
Service

JMSQueue
ServerSecurityInterceptor

JMSQueue
ServerSecurityInterceptor
Interceptor

Producer
TracingInterceptor

Producer Unified Invocation Layer


…..
UIL2 JMSDestination
JMSDestination MDB
MDB
Session
Session Connection
Connection UIL2
Invoker Manager
Manager Container
Container
Service
Service Invoker JMSTopic
JMSTopic
Tracing

Consumer
Consumer
JMSTopic
JMSTopic

JVM
JVMILIL
Service
Service

Remote Client VM
Security
Security State
State Message
Message
Manager
Manager Manager
Manager Cache
Cache

Persistence
Persistence
JaasSecurityManager
JaasSecurityManager Manager
Manager

JBossMQ VM
© JBoss, Inc. 2003-2005. 14

7
The inflow of a message through JBossMQ
Professional Open Source™
2. The ConnectionFactory.
1. Sending - How does it get bound in
the message JNDI?
on the client
side

ConnectionFactory
ConnectionFactory HTTP
HTTPILIL
Service
Service

JMSQueue

ServerSecurityInterceptor
JMSQueue

ServerSecurityInterceptor
Interceptor
Producer

TracingInterceptor
Producer Unified Invocation Layer
…..
UIL2 JMSDestination
JMSDestination MDB
MDB
Session
Session Connection
Connection UIL2
Invoker Manager
Manager Container
Container
Service
Service Invoker JMSTopic
JMSTopic

Tracing
Consumer
Consumer
JMSTopic
JMSTopic

JVM
JVMILIL
Service
Service

Remote Client VM
Security
Security State
State Message
Message
Manager
Manager Manager
Manager Cache
Cache
3. The Invocation Layers.
- How do they work?
- How to deploy them?
- How to configure them?
- How to secure them? Persistence
Persistence
JaasSecurityManager
JaasSecurityManager Manager
Manager

JBossMQ VM
© JBoss, Inc. 2003-2005. 15

The inflow of a message through JBossMQ


Professional Open Source™
2. The ConnectionFactory.
1. Sending 4. The Invoker and
- How does it get bound in
the message the interceptor chain
JNDI?
on the client
side

ConnectionFactory
ConnectionFactory HTTP
HTTPILIL
Service
Service

JMSQueue
ServerSecurityInterceptor

JMSQueue
ServerSecurityInterceptor
Interceptor

Producer
TracingInterceptor

Producer Unified Invocation Layer


…..
UIL2 JMSDestination
JMSDestination MDB
MDB
Session
Session Connection
Connection UIL2
Invoker Manager
Manager Container
Container
Service
Service Invoker JMSTopic
JMSTopic
Tracing

Consumer
Consumer
JMSTopic
JMSTopic

JVM
JVMILIL
Service
Service

Remote Client VM
Security
Security State
State Message
Message
Manager
Manager Manager
Manager Cache
Cache
3. The Invocation Layers.
- How do they work?
- How to deploy them?
- How to configure them?
- How to secure them? Persistence
Persistence
JaasSecurityManager
JaasSecurityManager Manager
Manager

JBossMQ VM
© JBoss, Inc. 2003-2005. 16

8
The inflow of a message through JBossMQ
Professional Open Source™
2. The ConnectionFactory.
1. Sending 4. The Invoker and
- How does it get bound in
the message the interceptor chain
JNDI?
on the client
side

ConnectionFactory
ConnectionFactory HTTP
HTTPILIL
Service
Service

JMSQueue

ServerSecurityInterceptor
JMSQueue

ServerSecurityInterceptor
Interceptor
Producer

TracingInterceptor
Producer Unified Invocation Layer
…..
UIL2 JMSDestination
JMSDestination MDB
MDB
Session
Session Connection
Connection UIL2
Invoker Manager
Manager Container
Container
Service
Service Invoker JMSTopic
JMSTopic

Tracing
Consumer
Consumer
JMSTopic
JMSTopic

JVM
JVMILIL
Service
Service

Remote Client VM
Security
Security State
State Message
Message
Manager
Manager Manager
Manager Cache
Cache
3. The Invocation Layers.
- How do they work?
- How to deploy them?
- How to configure them?
- How to secure them? Persistence
Persistence
JaasSecurityManager
JaasSecurityManager Manager
Manager
5. Configuring
the JBossMQ
JBossMQ VM security

© JBoss, Inc. 2003-2005. 17

The inflow of a message through JBossMQ


Professional Open Source™
2. The ConnectionFactory.
1. Sending 4. The Invoker and
- How does it get bound in
the message the interceptor chain
JNDI?
on the client
side
6. The
ConnectionFactory DestinationManager
ConnectionFactory HTTP
HTTPILIL
Service
Service

JMSQueue
ServerSecurityInterceptor

JMSQueue
ServerSecurityInterceptor
Interceptor

Producer
TracingInterceptor

Producer Unified Invocation Layer


…..
UIL2 JMSDestination
JMSDestination MDB
MDB
Session
Session Connection
Connection UIL2
Invoker Manager
Manager Container
Container
Service
Service Invoker JMSTopic
JMSTopic
Tracing

Consumer
Consumer
JMSTopic
JMSTopic

JVM
JVMILIL
Service
Service

Remote Client VM
Security
Security State
State Message
Message
Manager
Manager Manager
Manager Cache
Cache
3. The Invocation Layers.
- How do they work?
- How to deploy them?
- How to configure them?
- How to secure them? Persistence
Persistence
JaasSecurityManager
JaasSecurityManager Manager
Manager
5. Configuring
the JBossMQ
JBossMQ VM security

© JBoss, Inc. 2003-2005. 18

9
The inflow of a message through JBossMQ
Professional Open Source™
2. The ConnectionFactory.
1. Sending 4. The Invoker and
- How does it get bound in
the message the interceptor chain 7. Deploying a
JNDI?
on the client destination
side
6. The
ConnectionFactory DestinationManager
ConnectionFactory HTTP
HTTPILIL
Service
Service

JMSQueue

ServerSecurityInterceptor
JMSQueue

ServerSecurityInterceptor
Interceptor
Producer

TracingInterceptor
Producer Unified Invocation Layer
…..
UIL2 JMSDestination
JMSDestination MDB
MDB
Session
Session Connection
Connection UIL2
Invoker Manager
Manager Container
Container
Service
Service Invoker JMSTopic
JMSTopic

Tracing
Consumer
Consumer
JMSTopic
JMSTopic

JVM
JVMILIL
Service
Service

Remote Client VM
Security
Security State
State Message
Message
Manager
Manager Manager
Manager Cache
Cache
3. The Invocation Layers.
- How do they work?
- How to deploy them?
- How to configure them?
- How to secure them? Persistence
Persistence
JaasSecurityManager
JaasSecurityManager Manager
Manager
5. Configuring
the JBossMQ
JBossMQ VM security

© JBoss, Inc. 2003-2005. 19

The inflow of a message through JBossMQ


Professional Open Source™
2. The ConnectionFactory.
1. Sending 4. The Invoker and
- How does it get bound in
the message the interceptor chain 7. Deploying a
JNDI?
on the client destination
side
6. The
ConnectionFactory DestinationManager
ConnectionFactory HTTP
HTTPILIL
Service
Service

JMSQueue
ServerSecurityInterceptor

JMSQueue
ServerSecurityInterceptor
Interceptor

Producer
TracingInterceptor

Producer Unified Invocation Layer


…..
UIL2 JMSDestination
JMSDestination MDB
MDB
Session
Session Connection
Connection UIL2
Invoker Manager
Manager Container
Container
Service
Service Invoker JMSTopic
JMSTopic
Tracing

Consumer
Consumer
JMSTopic
JMSTopic

JVM
JVMILIL
Service
Service
8. Configuring
Remote Client VM the message
softening
Security
Security State
State Message
Message
Manager
Manager Manager
Manager Cache
Cache
3. The Invocation Layers.
- How do they work?
- How to deploy them?
- How to configure them?
- How to secure them? Persistence
Persistence
JaasSecurityManager
JaasSecurityManager Manager
Manager
5. Configuring
the JBossMQ
JBossMQ VM security

© JBoss, Inc. 2003-2005. 20

10
The inflow of a message through JBossMQ
Professional Open Source™
2. The ConnectionFactory.
1. Sending 4. The Invoker and
- How does it get bound in
the message the interceptor chain 7. Deploying a
JNDI?
on the client destination
side
6. The
ConnectionFactory DestinationManager
ConnectionFactory HTTP
HTTPILIL
Service
Service

JMSQueue

ServerSecurityInterceptor
JMSQueue

ServerSecurityInterceptor
Interceptor
Producer

TracingInterceptor
Producer Unified Invocation Layer
…..
UIL2 JMSDestination
JMSDestination MDB
MDB
Session
Session Connection
Connection UIL2
Invoker Manager
Manager Container
Container
Service
Service Invoker JMSTopic
JMSTopic

Tracing
Consumer
Consumer
JMSTopic
JMSTopic

JVM
JVMILIL
Service
Service
8. Configuring
Remote Client VM the message
softening
Security
Security State
State Message
Message
Manager
Manager Manager
Manager Cache
Cache
3. The Invocation Layers.
- How do they work?
- How to deploy them?
- How to configure them?
- How to secure them? Persistence
Persistence
JaasSecurityManager
JaasSecurityManager Manager
Manager
5. Configuring
the JBossMQ 9. Configuring
JBossMQ VM security the persistence

© JBoss, Inc. 2003-2005. 21

The inflow of a message through JBossMQ


Professional Open Source™
2. The ConnectionFactory.
1. Sending 4. The Invoker and
- How does it get bound in
the message the interceptor chain 7. Deploying a
JNDI?
on the client destination
side
6. The
ConnectionFactory DestinationManager 10. The MDB
ConnectionFactory HTTP
HTTPILIL Container
Service
Service

JMSQueue
ServerSecurityInterceptor

JMSQueue
ServerSecurityInterceptor
Interceptor

Producer
TracingInterceptor

Producer Unified Invocation Layer


…..
UIL2 JMSDestination
JMSDestination MDB
MDB
Session
Session Connection
Connection UIL2
Invoker Manager
Manager Container
Container
Service
Service Invoker JMSTopic
JMSTopic
Tracing

Consumer
Consumer
JMSTopic
JMSTopic

JVM
JVMILIL
Service
Service
8. Configuring
Remote Client VM the message
softening
Security
Security State
State Message
Message
Manager
Manager Manager
Manager Cache
Cache
3. The Invocation Layers.
- How do they work?
- How to deploy them?
- How to configure them?
- How to secure them? Persistence
Persistence
JaasSecurityManager
JaasSecurityManager Manager
Manager
5. Configuring
the JBossMQ 9. Configuring
JBossMQ VM security the persistence

© JBoss, Inc. 2003-2005. 22

11
The Client Side
Professional Open Source™

To send/receive a message
– Look-up the ConnectionFactory and the Destination.
– Create a Connection, Session a MessageProducer and a
MessageConsumer.
– If you want to send messages, don’t forget to start() the Connection!

import
import javax.jms.*;
javax.jms.*;
public
public static
static void
void main(String[]
main(String[] args)
args) throws
throws Exception
Exception {{
Context
Context context
context == new
new InitialContext();
InitialContext();
ConnectionFactory
ConnectionFactory connectionFactory
connectionFactory == (ConnectionFactory)context.lookup("ConnectionFactory");
(ConnectionFactory)context.lookup("ConnectionFactory");
Destination
Destination topic
topic == (Destination)context.lookup(“topic/MyTopic”);
(Destination)context.lookup(“topic/MyTopic”);
Connection
Connection connection
connection == connectionFactory.createConnection();
connectionFactory.createConnection();
Session
Session session
session == connection.createSession(true,
connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
Session.AUTO_ACKNOWLEDGE);
MessageProducer
MessageProducer producer
producer == session.createProducer(topic);
session.createProducer(topic);
TextMessage
TextMessage textMessage = session.createTextMessage(“some text”);
textMessage = session.createTextMessage(“some text”);
connection.start();
connection.start();
producer.send(textMessage);
producer.send(textMessage);
connection.close();
connection.close();
}}

© JBoss, Inc. 2003-2005. 23

The ConnectionFactory
Professional Open Source™

A ConnectionFactory
– Is a JMS Administered Object.
– Encapsulates a set of connection configuration parameters that has been
defined by the JMS server administrator.
– A client uses it to create a connection with a JMS provider.

In JBossMQ, the ConnectionFactories are bound in JNDI by the


Invocation Layers, during deployment.
– UIL2 binds "ConnectionFactory" and "XAConnectionFactory“.
– HTTPIL binds "HTTPConnectionFactory" and "HTTPXAConnectionFactory“
– JVM IL binds "java:/ConnectionFactory" and "java:/XAConnectionFactory“.

© JBoss, Inc. 2003-2005. 24

12
The Invocation Layers
Professional Open Source™

An Invocation Layer is a service responsible for handling client-to-server and


server-to-client communication over an arbitrary protocol.

Is made up of two interfaces:


– ServerIL
• a serializable object implementing this interface is included in the
ConnectionFactory.
• The client's connection will use it to send requests that are handled by the
ServerILService on the server.
– ClientIL
• a serializable object implementing this interface is created on the client and
sent to the server. It allows the server to invoke back on the client's
ClientILService (mainly to push messages to the client as they arrive).

Available implementations:
– Unified Invocation Layer Version 2 (UIL2)
– HTTPIL
– JVMIL

© JBoss, Inc. 2003-2005. 25

The Unified Invocation Layer Version 2


Professional Open Source™

UIL2 uses a single TCP socket over which multiplexes client-to-server


and server-to-client messages.
– Convenient when the client is protected by a firewall that denies inbound
connections.
– Asynchronously sends and receives messages at transport level, avoiding
a blocking round-trip at socket level.
– The recommended Invocation Layer for remote access.

Unified Invocation Layer UIL2


ServerSocket
ServerSocket
UILServerIL
UILServerIL ManagerHandler
ManagerHandler

Socket
Socket Socket
Socket JMSServerInvoker
JMSServerInvoker
Connection
Connection Manager
Manager Manager
Manager

UILClientILService
UILClientILService UILServerIL
UILServerIL

Remote Client VM JBoss VM

© JBoss, Inc. 2003-2005. 26

13
UIL2 Deployment and Configuration
Professional Open Source™

UIL2 is a JBoss service so it is deployed by placing a service


deployment descriptor (uil2-service.xml) in deploy/jms.
Remove it if you don't use it!

<?xml
<?xml version="1.0"
version="1.0" encoding="UTF-8"?>
encoding="UTF-8"?>
<server>
<server>
<mbean
<mbean code="org.jboss.mq.il.uil2.UILServerILService“
code="org.jboss.mq.il.uil2.UILServerILService“
name="jboss.mq:service=InvocationLayer,type=UIL2">
name="jboss.mq:service=InvocationLayer,type=UIL2">
<!--
<!-- The
The server
server chain
chain -->
-->
<depends
<depends optional-attribute-name="Invoker">jboss.mq:service=Invoker</depends>
optional-attribute-name="Invoker">jboss.mq:service=Invoker</depends>
<!--
<!-- JNDI
JNDI binding
binding -->
-->
<attribute
<attribute name="ConnectionFactoryJNDIRef">ConnectionFactory</attribute>
name="ConnectionFactoryJNDIRef">ConnectionFactory</attribute>
<!--
<!-- JNDI
JNDI binding
binding for
for XA
XA -->
-->
<attribute
<attribute name="XAConnectionFactoryJNDIRef">XAConnectionFactory</attribute>
name="XAConnectionFactoryJNDIRef">XAConnectionFactory</attribute>
<!--
<!-- The
The bind
bind address
address -->
-->
<attribute
<attribute name="BindAddress">${jboss.bind.address}</attribute>
name="BindAddress">${jboss.bind.address}</attribute>
(continued
(continued …)
…)

© JBoss, Inc. 2003-2005. 27

UIL2 Deployment Descriptor


Professional Open Source™

(…
(… continued)
continued)
<!--
<!-- The
The bind
bind port
port -->
-->
<attribute
<attribute name="ServerBindPort">8093</attribute>
name="ServerBindPort">8093</attribute>
<!--
<!-- The
The ping
ping period
period in
in millis
millis -->
-->
<attribute
<attribute name="PingPeriod">60000</attribute>
name="PingPeriod">60000</attribute>
<!--
<!-- Whether
Whether tcp/ip
tcp/ip does
does not
not wait
wait for
for buffer
buffer fills
fills -->
-->
<attribute
<attribute name="EnableTcpNoDelay">true</attribute>
name="EnableTcpNoDelay">true</attribute>
<!--
<!-- Used
Used to
to disconnect
disconnect thethe client
client ifif there
there is
is no
no activity
activity -->
-->
<!--
<!-- Ensure
Ensure this
this is
is greater
greater than
than the
the ping
ping period
period -->
-->
<attribute
<attribute name="ReadTimeout">120000</attribute>
name="ReadTimeout">120000</attribute>
<!--
<!-- The
The size
size of
of the
the buffer
buffer (in
(in bytes)
bytes) wrapping
wrapping the
the socket
socket -->
-->
<!--
<!-- The
The buffer
buffer is
is flushed
flushed after
after each
each request
request -->
-->
<attribute
<attribute name="BufferSize">2048</attribute>
name="BufferSize">2048</attribute>
<!--
<!-- Large
Large messages
messages may may block
block the
the ping/pong
ping/pong -->
-->
<!--
<!-- AA pong
pong is
is simulated
simulated after
after each
each chunk
chunk (in
(in bytes)
bytes) for
for both
both reading
reading and
and writing
writing -->
-->
<!--
<!-- ItIt must
must be
be larger
larger than
than the
the buffer
buffer size
size -->
-->
<attribute
<attribute name="ChunkSize">1000000</attribute>
name="ChunkSize">1000000</attribute>
</mbean>
</mbean>
</server>
</server>

© JBoss, Inc. 2003-2005. 28

14
UIL2 Configuration (1)
Professional Open Source™

ConnectionFactoryJNDIRef
– The JNDI name used to bind the ConnectionFactory corresponding to this
IL.
XAConnectionFactoryJNDIRef
– The JNDI name used to bind the XAConnectionFactory corresponding to
this IL.
BindAddress
– The interface to bind to.
– Useful for a multihomed machine.
ServerBindPort
– The port UIL2 service will listen on.
PingPeriod
– The interval, in milliseconds, after which the client sends a ping message
to the server to validate the connection.
– A zero value disables pinging.

© JBoss, Inc. 2003-2005. 29

UIL2 Configuration (2)


Professional Open Source™

EnableTcpNoDelay
– If enabled, the socket sends a TCP/IP packet as soon as the request is flushed,
without waiting to fill the buffer.
– Improves the request response time.
ReadTimeout
– The period, in milliseconds, passed as SoTimeout value to the UIL2 socket. This
allows detection of dead sockets.
– This value must be larger than the PingPeriod.
ServerSocketFactory
– The javax.net.ServerSocketFactory class to be used to create the service's
ServerSocket.
– Typically used to secure the connection using SSL sockets.
ClientSocketFactory
– The javax.net.ServerSocketFactory class to be used to create the client sockets.
– Typically used to secure the connection using SSL sockets.
SecurityDomain
– Specifies the JNDI name of the JBoss security domain to use with JBoss SSL
aware socket factories.

© JBoss, Inc. 2003-2005. 30

15
Securing the UIL2 (1)
Professional Open Source™

1. Generate a private-public key pair, using keytool.

>> keytool
keytool -genkey
-genkey -alias
-alias jbossmq
jbossmq -keyalg
-keyalg RSA
RSA -keystore
-keystore jbossmq.keystore
jbossmq.keystore -validity
-validity 3650
3650

Copy the keystore file in the server’s ‘conf’ directory.


2. Configure a new "SSL" security domain, that uses the previously created
keystore. Add a new MBean configuration to a new file ‘ssl-domain-
service.xml’ and deploy that file in the ‘deploy’ directory.

<?xml
<?xml version="1.0"
version="1.0" encoding="UTF-8"?>
encoding="UTF-8"?>
<server>
<server>
<mbean
<mbean code="org.jboss.security.plugins.JaasSecurityDomain"
code="org.jboss.security.plugins.JaasSecurityDomain"
name="jboss.security:service=JaasSecurityDomain,domain=SSL">
name="jboss.security:service=JaasSecurityDomain,domain=SSL">
<constructor>
<constructor>
<arg
<arg type="java.lang.String"
type="java.lang.String" value="SSL"/>
value="SSL"/>
</constructor>
</constructor>
<attribute
<attribute name="KeyStoreURL">resource:jbossmq.keystore</attribute>
name="KeyStoreURL">resource:jbossmq.keystore</attribute>
<attribute
<attribute name="KeyStorePass">jbossmq</attribute>
name="KeyStorePass">jbossmq</attribute>
</mbean>
</mbean>
</server>
</server>

© JBoss, Inc. 2003-2005. 31

Securing the UIL2 (2)


Professional Open Source™

3. Modify the UIL2 deployment descriptor to enable the security


domain and to use the SSL socket factories.

<?xml
<?xml version="1.0"
version="1.0" encoding="UTF-8"?>
encoding="UTF-8"?>
<server>
<server>
<mbean
<mbean code="org.jboss.mq.il.uil2.UILServerILService"
code="org.jboss.mq.il.uil2.UILServerILService"
name="jboss.mq:service=InvocationLayer,type=UIL2">
name="jboss.mq:service=InvocationLayer,type=UIL2">
….
….
<!--
<!-- SSL
SSL Socket
Socket Factories
Factories -->
-->
<attribute
<attribute name="ClientSocketFactory">org.jboss.security.ssl.ClientSocketFactory</attribute>
name="ClientSocketFactory">org.jboss.security.ssl.ClientSocketFactory</attribute>
<attribute
<attribute name="ServerSocketFactory">org.jboss.security.ssl.DomainServerSocketFactory</attribute>
name="ServerSocketFactory">org.jboss.security.ssl.DomainServerSocketFactory</attribute>
<!--
<!-- The
The SSL-aware
SSL-aware security
security domain
domain -->
-->
<attribute
<attribute name="SecurityDomain">java:/jaas/SSL</attribute>
name="SecurityDomain">java:/jaas/SSL</attribute>
</mbean>
</mbean>
</server>
</server>

© JBoss, Inc. 2003-2005. 32

16
Securing the UIL2 (3)
Professional Open Source™

4. Create the truststore that will be used by the client.

>> keytool
keytool -export
-export -alias
-alias jbossmq
jbossmq -keystore
-keystore jbossmq.keystore
jbossmq.keystore -rfc
-rfc -file
-file jbossmq.cer
jbossmq.cer
Enter
Enter keystore
keystore password:
password: jbossmq
jbossmq
...
...

>> keytool
keytool -import
-import -alias
-alias jbossmq
jbossmq -file
-file jbossmq.cer
jbossmq.cer -keystore
-keystore jbossmq.truststore
jbossmq.truststore
Enter
Enter keystore
keystore password:
password: jbossmq
jbossmq
...
...

5. Set the VM system properties in client and server


-Djavax.net.ssl.trustStore=jbossmq.truststore
-Djavax.net.ssl.trustStorePassword=jbossmq
and copy ‘jbossmq.trustore’ in the local directory.

© JBoss, Inc. 2003-2005. 33

The Invoker
Professional Open Source™

JMSServerInvoker implements the Invoker interface.


The invoker is the target of the Invocation Layer services.
Has the responsibility to pass the request to the ‘nextInterceptor’ in the
chain.

HTTP
HTTP IL
IL
ServerSecurityInterceptor
ServerSecurityInterceptor

Service
Service
TracingInterceptor
TracingInterceptor

HTTP
HTTP IL
IL JMSDestination
JMSDestination
JMSServerInvoker
JMSServerInvoker
Service
Service Manager
Manager

HTTP
HTTP IL
IL
Service
Service

© JBoss, Inc. 2003-2005. 34

17
The Interceptor Chain
Professional Open Source™

An implementation of the "Chain of Responsibility" pattern


The default configuration currently contains three interceptors:
– The TracingInterceptor
– The SecurityInterceptor
• Performs authentication and authorization of the requests.
– The JMDDestinationManager (the main server)
• Contains a map of JMSDestinations
You can implement your own JBossMQ interceptor
– It must be a JBoss Service.
– It must expose a “nextInterceptor” managed attribute.
– It must implement the org.jboss.mq.server.JMSServerInterceptor or
extend org.jboss.mq.server.JMSServerInterceptorSupport.
– You can insert it in the interceptor chain by adding the service declaration
to ‘jbossmq-service.xml’.

© JBoss, Inc. 2003-2005. 35

The Security Interceptor


Professional Open Source™

The Security Interceptor delegates authentication and authorization of


the requests to the JBossMQ SecurityManager.

The JBossMQ security infrastructure manages three types of security


information:
– Authentication information (username and passwords or other type of
security credentials). Authentication is delegated to a JBossSX
JaasSecurityManager.
– Principal to Role mapping. Delegated to the JaasSecurityManager.
– Permissions to Role mapping, relative to a destination.
• Specifies what roles are required to read/write from/to destination and
to create a durable subscription on a topic.
• The permissions are declared in the destination's deployment
descriptor.

© JBoss, Inc. 2003-2005. 36

18
The Security Manager
Professional Open Source™

The SecurityManager maintains a security configuration map


– Destination names are mapped to destination SecurityMetadata.
– The map is updated with each deployment/undeployment of a destination.

The SecurityManager delegates the authentication of a request to JaasSecurityManager


instance
– Specify the JNDI name of the JaasSecurityManager as the value of the SecurityManager’s
"SecurityDomain“ attribute.

The SecurityManager MBean is configured in the ‘jbossmq-service.xml’ deployment


descriptor.
….
….
<mbean
<mbean code="org.jboss.mq.security.SecurityManager"
code="org.jboss.mq.security.SecurityManager" name="jboss.mq:service=SecurityManager">
name="jboss.mq:service=SecurityManager">
<attribute
<attribute name="DefaultSecurityConfig">
name="DefaultSecurityConfig">
<security><role
<security><role name="guest"
name="guest" read="true"
read="true" write="true"
write="true" create="true"/></security>
create="true"/></security>
</attribute>
</attribute>
<attribute
<attribute name="SecurityDomain">java:/jaas/jbossmq</attribute>
name="SecurityDomain">java:/jaas/jbossmq</attribute>
<depends
<depends optional-attribute-name="NextInterceptor">jboss.mq:service=DestinationManager</depends>
optional-attribute-name="NextInterceptor">jboss.mq:service=DestinationManager</depends>
</mbean>
</mbean>
….
….

© JBoss, Inc. 2003-2005. 37

Authentication (1)
Professional Open Source™

The JaasSecurityManager’s LoginModule stack is configured in ‘login-config.xml’:

….
….

<application-policy
<application-policy name
name == "jbossmq">
"jbossmq">
<authentication>
<authentication>
<login-module
<login-module code
code == "org.jboss.security.auth.spi.DatabaseServerLoginModule"
"org.jboss.security.auth.spi.DatabaseServerLoginModule"
flag
flag == "required">
"required">
<module-option
<module-option name
name == "unauthenticatedIdentity">guest</module-option>
"unauthenticatedIdentity">guest</module-option>
<module-option
<module-option name
name == "dsJndiName">java:/DefaultDS</module-option>
"dsJndiName">java:/DefaultDS</module-option>
<module-option name = "principalsQuery">
<module-option name = "principalsQuery">
SELECT
SELECT PASSWD
PASSWD FROMFROM JMS_USERS
JMS_USERS WHERE
WHERE USERID=?</module-option>
USERID=?</module-option>
<module-option
<module-option name
name == "rolesQuery">
"rolesQuery">
SELECT
SELECT ROLEID, 'Roles' FROM JMS_ROLES WHERE USERID=?</module-option>
ROLEID, 'Roles' FROM JMS_ROLES WHERE USERID=?</module-option>
</login-module>
</login-module>
</authentication>
</authentication>
</application-policy>
</application-policy>
….
….

© JBoss, Inc. 2003-2005. 38

19
Authentication (2)
Professional Open Source™

If using a DynamicStateManager, the credentials are stored in ‘conf/jbossmq-


state.xml’, and the JaasSecurityManager delegates to the StateManager:

….
….
<application-policy
<application-policy name
name == "jbossmq">
"jbossmq">
<authentication>
<authentication>
<login-module code = "org.jboss.mq.sm.file.DynamicLoginModule"
<login-module code = "org.jboss.mq.sm.file.DynamicLoginModule"
flag
flag == "required">
"required">
<module-option
<module-option name
name == "unauthenticatedIdentity">guest</module-option>
"unauthenticatedIdentity">guest</module-option>
<module-option
<module-option name
name == "sm.objectname">jboss.mq:service=StateManager</module-option>
"sm.objectname">jboss.mq:service=StateManager</module-option>
</login-module>
</login-module>
</authentication>
</authentication>
</application-policy>
</application-policy>
….
….

The SecurityManager maintains an authentication cache, which maps session


IDs to SubjectInfo instances.
Once authenticated, the user’s SubjectInfo is added to the authenticated
cache.

© JBoss, Inc. 2003-2005. 39

Authorization
Professional Open Source™

The SecurityManager authorizes the requests


– add a message to a destination.
– create/delete durable subscriptions on a topic.
It maintains a security metadata map.
– Security meta data is added to the map every time a Queue or Topic is deployed.
– Can be configured using the ‘SecurityConf’ attribute of the Destination's deployment
descriptor.
– The typical destination deployment descriptor is ‘deploy/jms/jbossmq-destinations-
service.xml’.
– Security meta data consists in roles (not user names) and permissions.

….
….
<mbean
<mbean code="org.jboss.mq.server.jmx.Queue"
code="org.jboss.mq.server.jmx.Queue"
name="jboss.mq.destination:service=Queue,name=testQueue">
name="jboss.mq.destination:service=Queue,name=testQueue">
....
....
<attribute
<attribute name="SecurityConf">
name="SecurityConf">
<security>
<security>
<role
<role name="guest"
name="guest" read="true"
read="true" write="true"/>
write="true"/>
<role
<role name="publisher"
name="publisher" read="true"
read="true" write="true"
write="true" create="false"/>
create="false"/>
</security>
</security>
</attribute>
</attribute>
</mbean>
</mbean>
….
….

© JBoss, Inc. 2003-2005. 40

20
The Destination Manager
Professional Open Source™

The JMSDestinationManager is the main broker for requests


– Maintains a map of destinations and forwards inbound messages to their
destinations.
– Maintains a map of client consumers and outbound messages to their
ClientConsumers.
– Maintains a reference to the StateManager and delegates durable subscription
related requests to the StateManager.
– Maintains a reference to the MessageCache.
– Maintains a reference to the PersistenceManager.

ServerSecurityInterceptor
destinations
ServerSecurityInterceptor
JMSQueue
JMSQueue
Interceptor
TracingInterceptor

…..
JMSTopic
JMSTopic
Tracing

JMSDestination
JMSDestination
Manager JMSTopic
JMSTopic
Manager

State
State Message
Message Persistence
Persistence
Manager
Manager Cache
Cache Manager
Manager

© JBoss, Inc. 2003-2005. 41

Destinations
Professional Open Source™

Queues are implemented as JMSQueues, which delegate to


PersistentQueues.
– SelectorPersistentQueue is an optimization of PersistentQueue for topic
subscriptions that have selectors.
Topics are implemented as JMSTopic.
– Non-durable subscriptions are implemented as a set of ExclusiveQueues.
– Durable subscriptions are implemented as a set of PersistentQueues.
Destinations are deployed as regular JBoss Services, using a JBoss
service deployment descriptor.
The predefined destination definitions are available in
‘deploy/jms/jbossmq-destinations-service.xml’
Destinations can be created or destroyed at runtime using
‘jboss.mq:service=DestinationManager’'s managed operations:
– createQueue()/destroyQueue()
– createTopic()/destroyTopic()

© JBoss, Inc. 2003-2005. 42

21
A Destination Deployment Descriptor
Professional Open Source™

A Destination is a regular JBoss MBean, and it is deployed as such:


<?xml
<?xml version="1.0"
version="1.0" encoding="UTF-8"?>
encoding="UTF-8"?>
<server>
<server>
<mbean
<mbean code="org.jboss.mq.server.jmx.Topic"
code="org.jboss.mq.server.jmx.Topic"
name="jboss.mq.destination:service=Topic,name=testTopic">
name="jboss.mq.destination:service=Topic,name=testTopic">
<depends
<depends optional-attribute-name="DestinationManager">jboss.mq:service=DestinationManager</depends>
optional-attribute-name="DestinationManager">jboss.mq:service=DestinationManager</depends>
<depends
<depends optional-attribute-name="SecurityManager">jboss.mq:service=SecurityManager</depends>
optional-attribute-name="SecurityManager">jboss.mq:service=SecurityManager</depends>
<attribute
<attribute name="SecurityConf">
name="SecurityConf">
<security>
<security>
<role
<role name="guest"
name="guest" read="true"
read="true" write="true"/>
write="true"/>
<role
<role name="publisher"
name="publisher" read="true"
read="true" write="true"
write="true" create="false"/>
create="false"/>
<role
<role name="durpublisher"
name="durpublisher" read="true"
read="true" write="true"
write="true" create="true"/>
create="true"/>
</security>
</security>
</attribute>
</attribute>
</mbean>
</mbean>
<mbean
<mbean code="org.jboss.mq.server.jmx.Queue"
code="org.jboss.mq.server.jmx.Queue"
name="jboss.mq.destination:service=Queue,name=testQueue">
name="jboss.mq.destination:service=Queue,name=testQueue">
<depends
<depends optional-attribute-name="DestinationManager">jboss.mq:service=DestinationManager</depends>
optional-attribute-name="DestinationManager">jboss.mq:service=DestinationManager</depends>
<depends optional-attribute-name="SecurityManager">jboss.mq:service=SecurityManager</depends>
<depends optional-attribute-name="SecurityManager">jboss.mq:service=SecurityManager</depends>
<attribute
<attribute name="SecurityConf">
name="SecurityConf">
<security>
<security>
<role
<role name="guest" read="true"
name="guest" read="true" write="true"/>
write="true"/>
<role
<role name="publisher"
name="publisher" read="true"
read="true" write="true"
write="true" create="false"/>
create="false"/>
</security>
</security>
</attribute>
</attribute>
</mbean>
</mbean>
</server>
</server>

© JBoss, Inc. 2003-2005. 43

Message Caching
Professional Open Source™

Each message sent to a destination is first cached:


– The JMS spec does not require NON_PERSISTENT messages to be
stored.
– However, if the messages are large and there are not enough queue
receivers or there are many durable subscribes, storing the messages in
memory could lead to an OutOfMemoryError.
– MessageCache is the solution for this behavior.
– Immediately after a Destination receives a message, caches it and it gets
a MessageReference.
– Instead of holding direct references to the messages the Destinations
holds a MessageReference.
– The MessageReference either holds a direct reference to the message or
a pointer to the message in an offline store.
– This allows the server to move messages in and out of memory.
– Messages are saved to disk when memory starts to become full, using a
LRU mechanism.

© JBoss, Inc. 2003-2005. 44

22
Message Softening
Professional Open Source™

The MessageCache softens the messages that have been transferred


to external storage.
– When the JVM's heap size passes the HighMemoryMark and starts to
approach the MaxMemoryMark, the MessageCache begins softening
messages.
– Converts hard referenced messages to SoftReferences in memory.
– Writes a persistent copy of the message to the CacheStore.
– Messages are softened using a least recently used algorithm.
– Typical settings for HighMemoryMark/MaxMemoryMark should be 80%
and 90% of the -Xmx setting. You need to leave room (10% of memory if
you set 90% for the max setting) to make sure there is spare memory to
cope with any large messages you send.

<mbean
<mbean code="org.jboss.mq.server.MessageCache"
code="org.jboss.mq.server.MessageCache"
name="jboss.mq:service=MessageCache">
name="jboss.mq:service=MessageCache">
<attribute
<attribute name="HighMemoryMark">50</attribute>
name="HighMemoryMark">50</attribute>
<attribute
<attribute name="MaxMemoryMark">60</attribute>
name="MaxMemoryMark">60</attribute>
<attribute
<attribute name="CacheStore">jboss.mq:service=PersistenceManager</attribute>
name="CacheStore">jboss.mq:service=PersistenceManager</attribute>
</mbean>
</mbean>

© JBoss, Inc. 2003-2005. 45

The Persistence Manager


Professional Open Source™

If we want persistence, the JMS Messages must be explicitly made persistent:

sender.send(message,
sender.send(message, DeliveryMode.PERSISTENT,
DeliveryMode.PERSISTENT, priority,
priority, 0);
0);

The PersistenceManager saves and restore PERSISTENT messages and


those NON_PERSISTENT messages that have been softened (cache
overflow).
Works in cooperation with MessageCache
– It maintains a transaction log for transactional sessions.
Available implementations:
– JDBC Persistence Manager
– File Persistence Manager
– Null Persistence Manager - for the case you only deal with NON_PERSISTENT
messages and you don't have access to a DataSource.

Note! the Null Persistence Manager doesn't offer you any protection from
running out of memory, since it "persists" messages in ... memory.

© JBoss, Inc. 2003-2005. 46

23
The JDBC Persistence Manager
Professional Open Source™

Thg JDBC Persistence Manager is the recommended persistence


manager
– JDBC2 and JDBC3 implementations available.
– Used for both persistent messages and on cache overflow.
– A production level database is recommended.
– Configured by default in ‘hsqldb-jdbc2-service.xml’.
– Typically the State Manager accesses the same persistence store, so if
you change the Persistence Manager, you also have to change the State
Manager configuration, available by default in ‘deploy/jms/hsqldb-jdbc-
state-service.xml’

<mbean
<mbean code="org.jboss.mq.pm.jdbc2.PersistenceManager“
code="org.jboss.mq.pm.jdbc2.PersistenceManager“
name="jboss.mq:service=PersistenceManager">
name="jboss.mq:service=PersistenceManager">
<depends
<depends optional-attribute-name="ConnectionManager">jboss.jca:service=LocalTxCM,name=DefaultDS
optional-attribute-name="ConnectionManager">jboss.jca:service=LocalTxCM,name=DefaultDS
</depends>
</depends>
<attribute
<attribute name="SqlProperties">
name="SqlProperties">
……
</attribute>
</attribute>
</mbean>
</mbean>

© JBoss, Inc. 2003-2005. 47

JDBC Persistence Manager’s SqlProperties


Professional Open Source™

<attribute
<attribute name="SqlProperties">
name="SqlProperties">
BLOB_TYPE=OBJECT_BLOB
BLOB_TYPE=OBJECT_BLOB
INSERT_TX
INSERT_TX == INSERT
INSERT INTO
INTO JMS_TRANSACTIONS
JMS_TRANSACTIONS (TXID) (TXID) values(?)
values(?)
INSERT_MESSAGE
INSERT_MESSAGE == INSERT
INSERT INTO
INTO JMS_MESSAGES
JMS_MESSAGES (MESSAGEID,
(MESSAGEID, DESTINATION,
DESTINATION, \\
MESSAGEBLOB,
MESSAGEBLOB, TXID, TXID, TXOP)
TXOP) VALUES(?,?,?,?,?)
VALUES(?,?,?,?,?)
SELECT_ALL_UNCOMMITED_TXS
SELECT_ALL_UNCOMMITED_TXS == SELECT SELECT TXID
TXID FROM
FROM JMS_TRANSACTIONS
JMS_TRANSACTIONS
SELECT_MAX_TX
SELECT_MAX_TX == SELECT
SELECT MAX(TXID)
MAX(TXID) FROM
FROM JMS_MESSAGES
JMS_MESSAGES
SELECT_MESSAGES_IN_DEST
SELECT_MESSAGES_IN_DEST == SELECT SELECT MESSAGEID,
MESSAGEID, MESSAGEBLOB
MESSAGEBLOB FROM FROM JMS_MESSAGES
JMS_MESSAGES \\
WHERE
WHERE DESTINATION=?
DESTINATION=?
SELECT_MESSAGE
SELECT_MESSAGE == SELECT
SELECT MESSAGEID,
MESSAGEID, MESSAGEBLOB
MESSAGEBLOB FROM FROM JMS_MESSAGES
JMS_MESSAGES \\
WHERE
WHERE MESSAGEID=?
MESSAGEID=? AND AND DESTINATION=?
DESTINATION=?
MARK_MESSAGE
MARK_MESSAGE == UPDATE
UPDATE JMS_MESSAGES
JMS_MESSAGES SET SET TXID=?,
TXID=?, TXOP=?
TXOP=? \\
WHERE MESSAGEID=? AND DESTINATION=?
WHERE MESSAGEID=? AND DESTINATION=?
UPDATE_MESSAGE
UPDATE_MESSAGE == UPDATE
UPDATE JMS_MESSAGES
JMS_MESSAGES SET SET MESSAGEBLOB=?
MESSAGEBLOB=? \\
WHERE
WHERE MESSAGEID=?
MESSAGEID=? AND AND DESTINATION=?
DESTINATION=?
UPDATE_MARKED_MESSAGES
UPDATE_MARKED_MESSAGES == UPDATE UPDATE JMS_MESSAGES
JMS_MESSAGES SET SET TXID=?,
TXID=?, TXOP=?
TXOP=? WHERE
WHERE TXOP=?
TXOP=?
UPDATE_MARKED_MESSAGES_WITH_TX
UPDATE_MARKED_MESSAGES_WITH_TX == UPDATE UPDATE JMS_MESSAGES
JMS_MESSAGES SET SET TXID=?,
TXID=?, TXOP=?
TXOP=? \\
WHERE
WHERE TXOP=?
TXOP=? ANDAND TXID=?
TXID=?
DELETE_MARKED_MESSAGES_WITH_TX
DELETE_MARKED_MESSAGES_WITH_TX == DELETE DELETE FROM
FROM JMS_MESSAGES
JMS_MESSAGES WHERE WHERE TXOP=?
TXOP=? AND
AND \\
JMS_MESSAGES.TXID
JMS_MESSAGES.TXID IN IN (SELECT
(SELECT TXID
TXID FROM
FROM JMS_TRANSACTIONS)
JMS_TRANSACTIONS)
DELETE_TX
DELETE_TX == DELETE
DELETE FROM
FROM JMS_TRANSACTIONS
JMS_TRANSACTIONS WHERE WHERE TXID
TXID == ??
DELETE_MARKED_MESSAGES
DELETE_MARKED_MESSAGES == DELETE DELETE FROM
FROM JMS_MESSAGES
JMS_MESSAGES WHERE WHERE TXID=?
TXID=? AND
AND TXOP=?
TXOP=?
DELETE_TEMPORARY_MESSAGES
DELETE_TEMPORARY_MESSAGES == DELETE DELETE FROM
FROM JMS_MESSAGES
JMS_MESSAGES WHERE WHERE TXOP='T'
TXOP='T'
DELETE_MESSAGE
DELETE_MESSAGE == DELETE
DELETE FROM
FROM JMS_MESSAGES
JMS_MESSAGES WHEREWHERE MESSAGEID=?
MESSAGEID=? AND AND DESTINATION=?
DESTINATION=?
CREATE_MESSAGE_TABLE
CREATE_MESSAGE_TABLE == CREATE CREATE CACHED
CACHED TABLE
TABLE JMS_MESSAGES
JMS_MESSAGES (( MESSAGEID
MESSAGEID INTEGER
INTEGER NOT
NOT NULL,
NULL, \\
DESTINATION
DESTINATION VARCHAR(255)
VARCHAR(255) NOT NOT NULL,
NULL, TXID
TXID INTEGER,
INTEGER, TXOP
TXOP CHAR(1),
CHAR(1), \\
MESSAGEBLOB
MESSAGEBLOB OBJECT,
OBJECT, PRIMARY
PRIMARY KEY KEY (MESSAGEID,
(MESSAGEID, DESTINATION)
DESTINATION) ))
CREATE_TX_TABLE
CREATE_TX_TABLE == CREATE
CREATE CACHED
CACHED TABLE
TABLE JMS_TRANSACTIONS
JMS_TRANSACTIONS (( TXID TXID INTEGER,
INTEGER, PRIMARY
PRIMARY KEY
KEY (TXID)
(TXID) ))
CREATE_TABLES_ON_STARTUP
CREATE_TABLES_ON_STARTUP == TRUE TRUE
</attribute>
</attribute>

© JBoss, Inc. 2003-2005. 48

24
The MDB Container
Professional Open Source™

JBoss creates an MDB Container for each deployed MDB:


– There is NO home and remote interface for an MDB.
– The MDBs cannot be directly invoked, the MDB Container receives messages from
a destination and forwards the messages to the beans.
– Messages are delivered to the MDB container by a set of Sessions which are part
of the ServeSessionPool.
– The Sessions call into the JMSContainerInvoker and the JMSContainerInvoker
detypes the invocation and passes it along the EJB container invocation chain.

The MDB Container


StdServerSessionPool MessageDrivenContainer
Interceptors
StdServerSession
StdServerSession JMSContainerInvoker

JVM Invocation Layer SpyConnectionConsumer


SpyXAConnection
StdServerSession
StdServerSession

JVMClientIL
JVMClientIL
….. …..
YourMDB

StdServerSession
StdServerSession

MessageListenerImpl MessageDrivenInstancePool

© JBoss, Inc. 2003-2005. 49

MDB Container Fine Tuning


Professional Open Source™

Why multiple ServerSessions?


– A JMS Session is a single-threaded context. Multiple Sessions allows us
to send multiple simultaneous invocations into the MDB Container.
– How to change the size of the ServerSessionPool? Change the <invoker-
proxy-binding> configuration or define a new one in ‘conf/standardjboss-
xml’
<invoker-proxy-binding>
<invoker-proxy-binding>
<name>message-driven-bean</name>
<name>message-driven-bean</name>
<invoker-mbean>default</invoker-mbean>
<invoker-mbean>default</invoker-mbean>
<proxy-factory>org.jboss.ejb.plugins.jms.JMSContainerInvoker</proxy-factory>
<proxy-factory>org.jboss.ejb.plugins.jms.JMSContainerInvoker</proxy-factory>
<proxy-factory-config>
<proxy-factory-config>
….
….
<MinimumSize>1</MinimumSize>
<MinimumSize>1</MinimumSize>
<MaximumSize>15</MaximumSize>
<MaximumSize>15</MaximumSize>


<proxy-factory-config>
<proxy-factory-config>
<invoker-proxy-binding>
<invoker-proxy-binding>

Other configuration/tuning options:


– Configure the container interceptor chain.
– Change the MDB instance pool size.

© JBoss, Inc. 2003-2005. 50

25
High Availability JBossMQ
Professional Open Source™

High Availability JBossMQ is implemented as a HASingleton Service


– Only one running JBossMQ instance is available on a cluster.
– If the JBossMQ master node fails, the JBossMQ instance fails-over to the
first available node.

Node
Node 22

Node
Node 33 Node
Node 22 Node
Node 33
JBossMQ
JBossMQ

Singleton Fail-Over

Node
Node 11 Node
Node 11

JBossMQ
JBossMQ JBossMQ
JBossMQ

Shared Database Shared Database


© JBoss, Inc. 2003-2005. 51

HA JBossMQ Features
Professional Open Source™

High Availability JBossMQ Features:

– Automatic server fail-over.


– Transparent client connectivity to HAJMS, by looking up the
ConnnectionFactories in HAJNDI.
– Lossless recovery after fail-over for messages targeted to queues and
topic durable subscribers *)
– Client notification via connection’s ExceptionListener on fail-over.
* Shared production grade database recommended. There is NO in-
memory replication of queued messages. The HA failover will work
only for PERSISTENT messages!

© JBoss, Inc. 2003-2005. 52

26
HA JBossMQ Deployment
Professional Open Source™

HAJMS is deployed as part of the "all" configuration.

Initially the JMS server is configured to persist data in a Hypersonic database


instance.
– Change this!!! If the master node fails, most likely the HSQL instance will fail so
your persistent message date won't be available.
– Normally you would be running a clustered application server against a more
sophisticated database shared amongst all application server nodes.

All nodes in the cluster must be configured identically in regard to the JMS
services and their persistent DataSource.

Services to configure:
– The Persistence Manager (described previously). The default configuration file is
‘server/all/deploy-hasingleton/jms/hsqldb-jdbc2-service.xml’.
– The Sate Manager (described previously. The default configuration file is
‘server/all/deploy-hasingleton/jms/hsqldb-jdbc-state-service.xml’.

© JBoss, Inc. 2003-2005. 53

Client-side fail-over detection


Professional Open Source™

The failover must be explicitly initiated from the client code:


– The error condition is detected installing an ExceptionListener.
– The failover completes after a new ConnectionFactory is looked up in
JNDI and a new Connection is created.


private
private void
void connect(Context
connect(Context context,
context, String
String topicName)
topicName) throws
throws Exception
Exception {{
ConnectionFactory
ConnectionFactory connectionFactory
connectionFactory == (ConnectionFactory)context.lookup("ConnectionFactory");
(ConnectionFactory)context.lookup("ConnectionFactory");
connection
connection == connectionFactory.createConnection();
connectionFactory.createConnection();
connection.setExceptionListener(new
connection.setExceptionListener(new FailoverListener());
FailoverListener());
Session
Session session
session == connection.createSession(false,
connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Session.AUTO_ACKNOWLEDGE);
....
....
connection.start();
connection.start();
}}
(continued
(continued …)
…)

© JBoss, Inc. 2003-2005. 54

27
Client-side fail-over detection
Professional Open Source™

(…
(… continued)
continued)
private
private class
class FailoverListener
FailoverListener implements
implements ExceptionListener
ExceptionListener {{
private
private static
static final
final int
int RETRIES
RETRIES == 5;
5;
public
public void
void onException(JMSException
onException(JMSException e)
e) {{
int
int retries
retries == RETRIES;
RETRIES;
while(retries--
while(retries-- >> 0)
0) {{
try
try {{
connection.close();
connection.close(); //// unregisters
unregisters the
the ExceptionListener
ExceptionListener
}}
catch(Exception
catch(Exception e2) e2) {{
//// II will
will get
get an
an Exception
Exception anyway,
anyway, since
since the
the connection
connection to
to the
the server
server is
is
//// broken,
broken, butbut disconnect()
disconnect() frees
frees up
up resouces
resouces associated
associated with
with the
the connection
connection
}}
try
try {{
connect(jndiContext,
connect(jndiContext, TOPIC_NAME);
TOPIC_NAME);
break;
break;
}}
catch(Exception
catch(Exception e2) e2) {{
e.printStackTrace();
e.printStackTrace();
}}
}}
}}
}}

© JBoss, Inc. 2003-2005. 55

JBossMQ Anti-Patterns
Professional Open Source™

What NOT to do with JBossMQ:


– Contested queues with selectors that spend most of their time
read/skipping messages that don't match the selector(s).
– MDB singletons because you can't handle concurrent delivery.
– Continually connecting/disconnecting to/from the server.
– Not understanding the transaction context (client operations are with the
queue/server, not with other clients).

© JBoss, Inc. 2003-2005. 56

28
What is next?
Professional Open Source™

While still one of the best open source JMS providers around,
JBossMQ could be still further improved in regards of:
– Performance
– High Availability features.

A complete reimplementation it is currently under way


– It will combine elements of a serverful and a serverless architecture.
– It will take advantage of multicast capabilities of JGroups to increase the
performance on LANs that support hardware multicast.
– It will add transparent failover for JMS clients.
– It will add in-memory message replication, so the HA failover will work for
NON_PERSISTENT messages, too.

© JBoss, Inc. 2003-2005. 57

29

You might also like