messaging

29
1 Professional Open Source™ © JBoss, Inc. 2003-2005. 1 8/2/2005 JBossMQ Messaging, JMS, JBossMQ Architecture, Advanced Configuration and Tuning © JBoss, Inc. 2003-2005. 2 Professional Open Source™ Topics 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

Upload: api-27341052

Post on 13-Nov-2014

269 views

Category:

Documents


2 download

DESCRIPTION

JBossMQ

TRANSCRIPT

Page 1: Messaging

1

Professional Open Source™

© JBoss, Inc. 2003-2005. 18/2/2005

JBossMQMessaging, JMS, JBossMQ Architecture, Advanced Configuration and Tuning

© JBoss, Inc. 2003-2005. 2

Professional Open Source™

Topics

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

Page 2: Messaging

2

© JBoss, Inc. 2003-2005. 3

Professional Open Source™

The Need for Messaging

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. 4

Professional Open Source™

Messaging Pros

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.

Page 3: Messaging

3

© JBoss, Inc. 2003-2005. 5

Professional Open Source™

Messaging Cons

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

© JBoss, Inc. 2003-2005. 6

Professional Open Source™

Java Message Service

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

Page 4: Messaging

4

© JBoss, Inc. 2003-2005. 7

Professional Open Source™

JMS Messaging Domains

QueueQueue

SenderSender

SenderSender

SenderSender

ReceiverReceiver

ReceiverReceiver

ReceiverReceiver

m7

send

Message

m6 m5 m4 m3

m1

receiv

e

receive

m2

TopicTopic

SenderSender

SenderSender

SenderSender

m1

send

Message

m1receiv

e

receive

m1

receive

m7

m1

ReceiverReceiver

ReceiverReceiver

ReceiverReceiver

© JBoss, Inc. 2003-2005. 8

Professional Open Source™

The JMS API

ConnectionFactoryConnectionFactory

ConnectionConnection

SessionSession

MessageMessage

DestinationDestination

MessageConsumerMessageConsumerMessageProducerMessageProducer

creates

creates

createscreates

creates

QueueConnectionFactoryQueueConnectionFactory

QueueConnectionQueueConnection

QueueSessionQueueSession

QueueQueue

QueueReceiverQueueReceiverQueueSenderQueueSender

creates

creates

createscreates

TopicConnectionFactoryTopicConnectionFactory

TopicConnectionTopicConnection

TopicSessionTopicSession

TopicTopic

TopicSubscriberTopicSubscriberTopicPublisherTopicPublisher

creates

creates

createscreates

Page 5: Messaging

5

© JBoss, Inc. 2003-2005. 9

Professional Open Source™

Reliability and JMS

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. 10

Professional Open Source™

JBossMQ Features

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

Page 6: Messaging

6

© JBoss, Inc. 2003-2005. 11

Professional Open Source™

JBossMQ – An Architectural Overview

ConnectionFactoryConnectionFactory

ProducerProducer

ConsumerConsumer

Remote Client VM

SessionSession ConnectionConnection

JBossMQ VM

Unified Invocation Layer

HTTP ILService

HTTP ILService

UIL2Service

UIL2Service

JVM ILService

JVM ILService

InvokerInvoker

SecurityManager

SecurityManager

JaasSecurityManagerJaasSecurityManager

MDBContainer

MDBContainer

…..

StateManager

StateManager

MessageCache

MessageCache

PersistenceManager

PersistenceManager

JMSQueueJMSQueue

JMSTopicJMSTopic

JMSTopicJMSTopicTra

cing

Inte

rcep

tor

Tra

cing

Inte

rcep

tor

Ser

verS

ecur

ityIn

terc

epto

rS

erve

rSec

urity

Inte

rcep

tor

JMSDestinationManager

JMSDestinationManager

© JBoss, Inc. 2003-2005. 12

Professional Open Source™

The inflow of a message through JBossMQ

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 …

Page 7: Messaging

7

© JBoss, Inc. 2003-2005. 13

Professional Open Source™

The inflow of a message through JBossMQ

ConnectionFactoryConnectionFactory

ProducerProducer

ConsumerConsumer

Remote Client VM

SessionSession ConnectionConnection

JBossMQ VM

Unified Invocation Layer

HTTP ILService

HTTP ILService

UIL2Service

UIL2Service

JVM ILService

JVM ILService

InvokerInvoker

SecurityManager

SecurityManager

JaasSecurityManagerJaasSecurityManager

MDBContainer

MDBContainer

…..

StateManager

StateManager

MessageCache

MessageCache

PersistenceManager

PersistenceManager

JMSQueueJMSQueue

JMSTopicJMSTopic

JMSTopicJMSTopicTra

cing

Inte

rcep

tor

Tra

cing

Inte

rcep

tor

Ser

verS

ecur

ityIn

terc

epto

rS

erve

rSec

urity

Inte

rcep

tor

JMSDestinationManager

JMSDestinationManager

1. Sending the message on the client

side

© JBoss, Inc. 2003-2005. 14

Professional Open Source™

The inflow of a message through JBossMQ

ConnectionFactoryConnectionFactory

ProducerProducer

ConsumerConsumer

Remote Client VM

SessionSession ConnectionConnection

JBossMQ VM

Unified Invocation Layer

HTTP ILService

HTTP ILService

UIL2Service

UIL2Service

JVM ILService

JVM ILService

InvokerInvoker

SecurityManager

SecurityManager

JaasSecurityManagerJaasSecurityManager

MDBContainer

MDBContainer

…..

StateManager

StateManager

MessageCache

MessageCache

PersistenceManager

PersistenceManager

JMSQueueJMSQueue

JMSTopicJMSTopic

JMSTopicJMSTopicTra

cing

Inte

rcep

tor

Tra

cing

Inte

rcep

tor

Ser

verS

ecur

ityIn

terc

epto

rS

erve

rSec

urity

Inte

rcep

tor

JMSDestinationManager

JMSDestinationManager

1. Sending the message on the client

side

2. The ConnectionFactory.- How does it get bound in JNDI?

Page 8: Messaging

8

© JBoss, Inc. 2003-2005. 15

Professional Open Source™

The inflow of a message through JBossMQ

ConnectionFactoryConnectionFactory

ProducerProducer

ConsumerConsumer

Remote Client VM

SessionSession ConnectionConnection

JBossMQ VM

Unified Invocation Layer

HTTP ILService

HTTP ILService

UIL2Service

UIL2Service

JVM ILService

JVM ILService

InvokerInvoker

SecurityManager

SecurityManager

JaasSecurityManagerJaasSecurityManager

MDBContainer

MDBContainer

…..

StateManager

StateManager

MessageCache

MessageCache

PersistenceManager

PersistenceManager

JMSQueueJMSQueue

JMSTopicJMSTopic

JMSTopicJMSTopicTra

cing

Inte

rcep

tor

Tra

cing

Inte

rcep

tor

Ser

verS

ecur

ityIn

terc

epto

rS

erve

rSec

urity

Inte

rcep

tor

JMSDestinationManager

JMSDestinationManager

1. Sending the message on the client

side

2. The ConnectionFactory.- How does it get bound in JNDI?

3. The Invocation Layers.- How do they work?- How to deploy them?- How to configure them?- How to secure them?

© JBoss, Inc. 2003-2005. 16

Professional Open Source™

The inflow of a message through JBossMQ

ConnectionFactoryConnectionFactory

ProducerProducer

ConsumerConsumer

Remote Client VM

SessionSession ConnectionConnection

JBossMQ VM

Unified Invocation Layer

HTTP ILService

HTTP ILService

UIL2Service

UIL2Service

JVM ILService

JVM ILService

InvokerInvoker

SecurityManager

SecurityManager

JaasSecurityManagerJaasSecurityManager

MDBContainer

MDBContainer

…..

StateManager

StateManager

MessageCache

MessageCache

PersistenceManager

PersistenceManager

JMSQueueJMSQueue

JMSTopicJMSTopic

JMSTopicJMSTopicTra

cing

Inte

rcep

tor

Tra

cing

Inte

rcep

tor

Ser

verS

ecur

ityIn

terc

epto

rS

erve

rSec

urity

Inte

rcep

tor

JMSDestinationManager

JMSDestinationManager

1. Sending the message on the client

side

2. The ConnectionFactory.- How does it get bound in JNDI?

3. The Invocation Layers.- How do they work?- How to deploy them?- How to configure them?- How to secure them?

4. The Invoker and the interceptor chain

Page 9: Messaging

9

© JBoss, Inc. 2003-2005. 17

Professional Open Source™

The inflow of a message through JBossMQ

ConnectionFactoryConnectionFactory

ProducerProducer

ConsumerConsumer

Remote Client VM

SessionSession ConnectionConnection

JBossMQ VM

Unified Invocation Layer

HTTP ILService

HTTP ILService

UIL2Service

UIL2Service

JVM ILService

JVM ILService

InvokerInvoker

SecurityManager

SecurityManager

JaasSecurityManagerJaasSecurityManager

MDBContainer

MDBContainer

…..

StateManager

StateManager

MessageCache

MessageCache

PersistenceManager

PersistenceManager

JMSQueueJMSQueue

JMSTopicJMSTopic

JMSTopicJMSTopicTra

cing

Inte

rcep

tor

Tra

cing

Inte

rcep

tor

Ser

verS

ecur

ityIn

terc

epto

rS

erve

rSec

urity

Inte

rcep

tor

JMSDestinationManager

JMSDestinationManager

1. Sending the message on the client

side

2. The ConnectionFactory.- How does it get bound in JNDI?

3. The Invocation Layers.- How do they work?- How to deploy them?- How to configure them?- How to secure them?

4. The Invoker and the interceptor chain

5. Configuring the JBossMQ

security

© JBoss, Inc. 2003-2005. 18

Professional Open Source™

The inflow of a message through JBossMQ

ConnectionFactoryConnectionFactory

ProducerProducer

ConsumerConsumer

Remote Client VM

SessionSession ConnectionConnection

JBossMQ VM

Unified Invocation Layer

HTTP ILService

HTTP ILService

UIL2Service

UIL2Service

JVM ILService

JVM ILService

InvokerInvoker

SecurityManager

SecurityManager

JaasSecurityManagerJaasSecurityManager

MDBContainer

MDBContainer

…..

StateManager

StateManager

MessageCache

MessageCache

PersistenceManager

PersistenceManager

JMSQueueJMSQueue

JMSTopicJMSTopic

JMSTopicJMSTopicTra

cing

Inte

rcep

tor

Tra

cing

Inte

rcep

tor

Ser

verS

ecur

ityIn

terc

epto

rS

erve

rSec

urity

Inte

rcep

tor

JMSDestinationManager

JMSDestinationManager

1. Sending the message on the client

side

2. The ConnectionFactory.- How does it get bound in JNDI?

3. The Invocation Layers.- How do they work?- How to deploy them?- How to configure them?- How to secure them?

4. The Invoker and the interceptor chain

5. Configuring the JBossMQ

security

6. The DestinationManager

Page 10: Messaging

10

© JBoss, Inc. 2003-2005. 19

Professional Open Source™

The inflow of a message through JBossMQ

ConnectionFactoryConnectionFactory

ProducerProducer

ConsumerConsumer

Remote Client VM

SessionSession ConnectionConnection

JBossMQ VM

Unified Invocation Layer

HTTP ILService

HTTP ILService

UIL2Service

UIL2Service

JVM ILService

JVM ILService

InvokerInvoker

SecurityManager

SecurityManager

JaasSecurityManagerJaasSecurityManager

MDBContainer

MDBContainer

…..

StateManager

StateManager

MessageCache

MessageCache

PersistenceManager

PersistenceManager

JMSQueueJMSQueue

JMSTopicJMSTopic

JMSTopicJMSTopicTra

cing

Inte

rcep

tor

Tra

cing

Inte

rcep

tor

Ser

verS

ecur

ityIn

terc

epto

rS

erve

rSec

urity

Inte

rcep

tor

JMSDestinationManager

JMSDestinationManager

1. Sending the message on the client

side

2. The ConnectionFactory.- How does it get bound in JNDI?

3. The Invocation Layers.- How do they work?- How to deploy them?- How to configure them?- How to secure them?

4. The Invoker and the interceptor chain

5. Configuring the JBossMQ

security

6. The DestinationManager

7. Deploying a destination

© JBoss, Inc. 2003-2005. 20

Professional Open Source™

The inflow of a message through JBossMQ

ConnectionFactoryConnectionFactory

ProducerProducer

ConsumerConsumer

Remote Client VM

SessionSession ConnectionConnection

JBossMQ VM

Unified Invocation Layer

HTTP ILService

HTTP ILService

UIL2Service

UIL2Service

JVM ILService

JVM ILService

InvokerInvoker

SecurityManager

SecurityManager

JaasSecurityManagerJaasSecurityManager

MDBContainer

MDBContainer

…..

StateManager

StateManager

MessageCache

MessageCache

PersistenceManager

PersistenceManager

JMSQueueJMSQueue

JMSTopicJMSTopic

JMSTopicJMSTopicTra

cing

Inte

rcep

tor

Tra

cing

Inte

rcep

tor

Ser

verS

ecur

ityIn

terc

epto

rS

erve

rSec

urity

Inte

rcep

tor

JMSDestinationManager

JMSDestinationManager

1. Sending the message on the client

side

2. The ConnectionFactory.- How does it get bound in JNDI?

3. The Invocation Layers.- How do they work?- How to deploy them?- How to configure them?- How to secure them?

4. The Invoker and the interceptor chain

5. Configuring the JBossMQ

security

6. The DestinationManager

7. Deploying a destination

8. Configuring the message softening

Page 11: Messaging

11

© JBoss, Inc. 2003-2005. 21

Professional Open Source™

The inflow of a message through JBossMQ

ConnectionFactoryConnectionFactory

ProducerProducer

ConsumerConsumer

Remote Client VM

SessionSession ConnectionConnection

JBossMQ VM

Unified Invocation Layer

HTTP ILService

HTTP ILService

UIL2Service

UIL2Service

JVM ILService

JVM ILService

InvokerInvoker

SecurityManager

SecurityManager

JaasSecurityManagerJaasSecurityManager

MDBContainer

MDBContainer

…..

StateManager

StateManager

MessageCache

MessageCache

PersistenceManager

PersistenceManager

JMSQueueJMSQueue

JMSTopicJMSTopic

JMSTopicJMSTopicTra

cing

Inte

rcep

tor

Tra

cing

Inte

rcep

tor

Ser

verS

ecur

ityIn

terc

epto

rS

erve

rSec

urity

Inte

rcep

tor

JMSDestinationManager

JMSDestinationManager

1. Sending the message on the client

side

2. The ConnectionFactory.- How does it get bound in JNDI?

3. The Invocation Layers.- How do they work?- How to deploy them?- How to configure them?- How to secure them?

4. The Invoker and the interceptor chain

5. Configuring the JBossMQ

security

6. The DestinationManager

7. Deploying a destination

8. Configuring the message softening

9. Configuring the persistence

© JBoss, Inc. 2003-2005. 22

Professional Open Source™

The inflow of a message through JBossMQ

ConnectionFactoryConnectionFactory

ProducerProducer

ConsumerConsumer

Remote Client VM

SessionSession ConnectionConnection

JBossMQ VM

Unified Invocation Layer

HTTP ILService

HTTP ILService

UIL2Service

UIL2Service

JVM ILService

JVM ILService

InvokerInvoker

SecurityManager

SecurityManager

JaasSecurityManagerJaasSecurityManager

MDBContainer

MDBContainer

…..

StateManager

StateManager

MessageCache

MessageCache

PersistenceManager

PersistenceManager

JMSQueueJMSQueue

JMSTopicJMSTopic

JMSTopicJMSTopicTra

cing

Inte

rcep

tor

Tra

cing

Inte

rcep

tor

Ser

verS

ecur

ityIn

terc

epto

rS

erve

rSec

urity

Inte

rcep

tor

JMSDestinationManager

JMSDestinationManager

1. Sending the message on the client

side

2. The ConnectionFactory.- How does it get bound in JNDI?

3. The Invocation Layers.- How do they work?- How to deploy them?- How to configure them?- How to secure them?

4. The Invoker and the interceptor chain

5. Configuring the JBossMQ

security

6. The DestinationManager

7. Deploying a destination

8. Configuring the message softening

10. The MDB Container

9. Configuring the persistence

Page 12: Messaging

12

© JBoss, Inc. 2003-2005. 23

Professional Open Source™

The Client Side

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 javax.jms.*;

public static void main(String[] args) throws Exception {

Context context = new InitialContext();ConnectionFactory connectionFactory = (ConnectionFactory)context.lookup("ConnectionFactory");Destination topic = (Destination)context.lookup(“topic/MyTopic”);

Connection connection = connectionFactory.createConnection();Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);MessageProducer producer = session.createProducer(topic);TextMessage textMessage = session.createTextMessage(“some text”);

connection.start();

producer.send(textMessage);

connection.close();}

import javax.jms.*;

public static void main(String[] args) throws Exception {

Context context = new InitialContext();ConnectionFactory connectionFactory = (ConnectionFactory)context.lookup("ConnectionFactory");Destination topic = (Destination)context.lookup(“topic/MyTopic”);

Connection connection = connectionFactory.createConnection();Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);MessageProducer producer = session.createProducer(topic);TextMessage textMessage = session.createTextMessage(“some text”);

connection.start();

producer.send(textMessage);

connection.close();}

© JBoss, Inc. 2003-2005. 24

Professional Open Source™

The ConnectionFactory

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“.

Page 13: Messaging

13

© JBoss, Inc. 2003-2005. 25

Professional Open Source™

The Invocation Layers

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. 26

Professional Open Source™

The Unified Invocation Layer Version 2

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.

ConnectionConnection

Remote Client VM JBoss VM

Unified Invocation Layer UIL2

UILServerILUILServerIL

UILClientILServiceUILClientILService

SocketManager

SocketManager

SocketManager

SocketManager JMSServerInvokerJMSServerInvoker

ServerSocketManagerHandler

ServerSocketManagerHandler

UILServerILUILServerIL

Page 14: Messaging

14

© JBoss, Inc. 2003-2005. 27

Professional Open Source™

UIL2 Deployment and Configuration

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 version="1.0" encoding="UTF-8"?>

<server>

<mbean code="org.jboss.mq.il.uil2.UILServerILService“name="jboss.mq:service=InvocationLayer,type=UIL2">

<!-- The server chain --><depends optional-attribute-name="Invoker">jboss.mq:service=Invoker</depends>

<!-- JNDI binding --><attribute name="ConnectionFactoryJNDIRef">ConnectionFactory</attribute>

<!-- JNDI binding for XA --><attribute name="XAConnectionFactoryJNDIRef">XAConnectionFactory</attribute>

<!-- The bind address --><attribute name="BindAddress">${jboss.bind.address}</attribute>

(continued …)

<?xml version="1.0" encoding="UTF-8"?>

<server>

<mbean code="org.jboss.mq.il.uil2.UILServerILService“name="jboss.mq:service=InvocationLayer,type=UIL2">

<!-- The server chain --><depends optional-attribute-name="Invoker">jboss.mq:service=Invoker</depends>

<!-- JNDI binding --><attribute name="ConnectionFactoryJNDIRef">ConnectionFactory</attribute>

<!-- JNDI binding for XA --><attribute name="XAConnectionFactoryJNDIRef">XAConnectionFactory</attribute>

<!-- The bind address --><attribute name="BindAddress">${jboss.bind.address}</attribute>

(continued …)

© JBoss, Inc. 2003-2005. 28

Professional Open Source™

UIL2 Deployment Descriptor

(… continued)

<!-- The bind port --><attribute name="ServerBindPort">8093</attribute>

<!-- The ping period in millis --><attribute name="PingPeriod">60000</attribute>

<!-- Whether tcp/ip does not wait for buffer fills --><attribute name="EnableTcpNoDelay">true</attribute>

<!-- Used to disconnect the client if there is no activity --><!-- Ensure this is greater than the ping period --><attribute name="ReadTimeout">120000</attribute>

<!-- The size of the buffer (in bytes) wrapping the socket --><!-- The buffer is flushed after each request --><attribute name="BufferSize">2048</attribute>

<!-- Large messages may block the ping/pong --><!-- A pong is simulated after each chunk (in bytes) for both reading and writing --><!-- It must be larger than the buffer size --><attribute name="ChunkSize">1000000</attribute>

</mbean>

</server>

(… continued)

<!-- The bind port --><attribute name="ServerBindPort">8093</attribute>

<!-- The ping period in millis --><attribute name="PingPeriod">60000</attribute>

<!-- Whether tcp/ip does not wait for buffer fills --><attribute name="EnableTcpNoDelay">true</attribute>

<!-- Used to disconnect the client if there is no activity --><!-- Ensure this is greater than the ping period --><attribute name="ReadTimeout">120000</attribute>

<!-- The size of the buffer (in bytes) wrapping the socket --><!-- The buffer is flushed after each request --><attribute name="BufferSize">2048</attribute>

<!-- Large messages may block the ping/pong --><!-- A pong is simulated after each chunk (in bytes) for both reading and writing --><!-- It must be larger than the buffer size --><attribute name="ChunkSize">1000000</attribute>

</mbean>

</server>

Page 15: Messaging

15

© JBoss, Inc. 2003-2005. 29

Professional Open Source™

UIL2 Configuration (1)

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. 30

Professional Open Source™

UIL2 Configuration (2)

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.

Page 16: Messaging

16

© JBoss, Inc. 2003-2005. 31

Professional Open Source™

Securing the UIL2 (1)

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

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.

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

<?xml version="1.0" encoding="UTF-8"?><server>

<mbean code="org.jboss.security.plugins.JaasSecurityDomain"name="jboss.security:service=JaasSecurityDomain,domain=SSL">

<constructor><arg type="java.lang.String" value="SSL"/>

</constructor>

<attribute name="KeyStoreURL">resource:jbossmq.keystore</attribute><attribute name="KeyStorePass">jbossmq</attribute>

</mbean></server>

<?xml version="1.0" encoding="UTF-8"?><server>

<mbean code="org.jboss.security.plugins.JaasSecurityDomain"name="jboss.security:service=JaasSecurityDomain,domain=SSL">

<constructor><arg type="java.lang.String" value="SSL"/>

</constructor>

<attribute name="KeyStoreURL">resource:jbossmq.keystore</attribute><attribute name="KeyStorePass">jbossmq</attribute>

</mbean></server>

© JBoss, Inc. 2003-2005. 32

Professional Open Source™

Securing the UIL2 (2)

3. Modify the UIL2 deployment descriptor to enable the security domain and to use the SSL socket factories.

<?xml version="1.0" encoding="UTF-8"?>

<server>

<mbean code="org.jboss.mq.il.uil2.UILServerILService"name="jboss.mq:service=InvocationLayer,type=UIL2">

….

<!-- SSL Socket Factories --><attribute name="ClientSocketFactory">org.jboss.security.ssl.ClientSocketFactory</attribute><attribute name="ServerSocketFactory">org.jboss.security.ssl.DomainServerSocketFactory</attribute>

<!-- The SSL-aware security domain --><attribute name="SecurityDomain">java:/jaas/SSL</attribute>

</mbean>

</server>

<?xml version="1.0" encoding="UTF-8"?>

<server>

<mbean code="org.jboss.mq.il.uil2.UILServerILService"name="jboss.mq:service=InvocationLayer,type=UIL2">

….

<!-- SSL Socket Factories --><attribute name="ClientSocketFactory">org.jboss.security.ssl.ClientSocketFactory</attribute><attribute name="ServerSocketFactory">org.jboss.security.ssl.DomainServerSocketFactory</attribute>

<!-- The SSL-aware security domain --><attribute name="SecurityDomain">java:/jaas/SSL</attribute>

</mbean>

</server>

Page 17: Messaging

17

© JBoss, Inc. 2003-2005. 33

Professional Open Source™

Securing the UIL2 (3)

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

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.

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

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

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

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

© JBoss, Inc. 2003-2005. 34

Professional Open Source™

The Invoker

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 IL Service

HTTP IL Service

HTTP IL Service

HTTP IL Service

HTTP IL Service

HTTP IL Service

JMSServerInvokerJMSServerInvoker

Tra

cing

Inte

rcep

tor

Tra

cing

Inte

rcep

tor

Ser

verS

ecur

ityIn

terc

epto

rS

erve

rSec

urity

Inte

rcep

tor

JMSDestinationManager

JMSDestinationManager

Page 18: Messaging

18

© JBoss, Inc. 2003-2005. 35

Professional Open Source™

The Interceptor Chain

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. 36

Professional Open Source™

The Security Interceptor

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.

Page 19: Messaging

19

© JBoss, Inc. 2003-2005. 37

Professional Open Source™

The Security Manager

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 code="org.jboss.mq.security.SecurityManager" name="jboss.mq:service=SecurityManager">

<attribute name="DefaultSecurityConfig"><security><role name="guest" read="true" write="true" create="true"/></security>

</attribute>

<attribute name="SecurityDomain">java:/jaas/jbossmq</attribute>

<depends optional-attribute-name="NextInterceptor">jboss.mq:service=DestinationManager</depends>

</mbean>….

….

<mbean code="org.jboss.mq.security.SecurityManager" name="jboss.mq:service=SecurityManager">

<attribute name="DefaultSecurityConfig"><security><role name="guest" read="true" write="true" create="true"/></security>

</attribute>

<attribute name="SecurityDomain">java:/jaas/jbossmq</attribute>

<depends optional-attribute-name="NextInterceptor">jboss.mq:service=DestinationManager</depends>

</mbean>….

© JBoss, Inc. 2003-2005. 38

Professional Open Source™

Authentication (1)

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

….

<application-policy name = "jbossmq">

<authentication><login-module code = "org.jboss.security.auth.spi.DatabaseServerLoginModule"

flag = "required">

<module-option name = "unauthenticatedIdentity">guest</module-option><module-option name = "dsJndiName">java:/DefaultDS</module-option><module-option name = "principalsQuery">

SELECT PASSWD FROM JMS_USERS WHERE USERID=?</module-option><module-option name = "rolesQuery">

SELECT ROLEID, 'Roles' FROM JMS_ROLES WHERE USERID=?</module-option>

</login-module></authentication>

</application-policy>….

….

<application-policy name = "jbossmq">

<authentication><login-module code = "org.jboss.security.auth.spi.DatabaseServerLoginModule"

flag = "required">

<module-option name = "unauthenticatedIdentity">guest</module-option><module-option name = "dsJndiName">java:/DefaultDS</module-option><module-option name = "principalsQuery">

SELECT PASSWD FROM JMS_USERS WHERE USERID=?</module-option><module-option name = "rolesQuery">

SELECT ROLEID, 'Roles' FROM JMS_ROLES WHERE USERID=?</module-option>

</login-module></authentication>

</application-policy>….

Page 20: Messaging

20

© JBoss, Inc. 2003-2005. 39

Professional Open Source™

Authentication (2)

If using a DynamicStateManager, the credentials are stored in ‘conf/jbossmq-state.xml’, and the JaasSecurityManager delegates to the StateManager:

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.

….

<application-policy name = "jbossmq"><authentication>

<login-module code = "org.jboss.mq.sm.file.DynamicLoginModule"flag = "required">

<module-option name = "unauthenticatedIdentity">guest</module-option><module-option name = "sm.objectname">jboss.mq:service=StateManager</module-option>

</login-module></authentication>

</application-policy>….

….

<application-policy name = "jbossmq"><authentication>

<login-module code = "org.jboss.mq.sm.file.DynamicLoginModule"flag = "required">

<module-option name = "unauthenticatedIdentity">guest</module-option><module-option name = "sm.objectname">jboss.mq:service=StateManager</module-option>

</login-module></authentication>

</application-policy>….

© JBoss, Inc. 2003-2005. 40

Professional Open Source™

Authorization

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 code="org.jboss.mq.server.jmx.Queue"

name="jboss.mq.destination:service=Queue,name=testQueue">....<attribute name="SecurityConf">

<security><role name="guest" read="true" write="true"/><role name="publisher" read="true" write="true" create="false"/>

</security></attribute>

</mbean>….

…. <mbean code="org.jboss.mq.server.jmx.Queue"

name="jboss.mq.destination:service=Queue,name=testQueue">....<attribute name="SecurityConf">

<security><role name="guest" read="true" write="true"/><role name="publisher" read="true" write="true" create="false"/>

</security></attribute>

</mbean>….

Page 21: Messaging

21

© JBoss, Inc. 2003-2005. 41

Professional Open Source™

The Destination Manager

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.

…..

Tra

cing

Inte

rcep

tor

Tra

cing

Inte

rcep

tor

Ser

verS

ecur

ityIn

terc

epto

rS

erve

rSec

urity

Inte

rcep

tor

JMSDestinationManager

JMSDestinationManager

StateManager

StateManager

MessageCache

MessageCache

PersistenceManager

PersistenceManager

destinations JMSQueueJMSQueue

JMSTopicJMSTopic

JMSTopicJMSTopic

© JBoss, Inc. 2003-2005. 42

Professional Open Source™

Destinations

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()

Page 22: Messaging

22

© JBoss, Inc. 2003-2005. 43

Professional Open Source™

A Destination Deployment Descriptor

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

<?xml version="1.0" encoding="UTF-8"?><server>

<mbean code="org.jboss.mq.server.jmx.Topic"name="jboss.mq.destination:service=Topic,name=testTopic">

<depends optional-attribute-name="DestinationManager">jboss.mq:service=DestinationManager</depends><depends optional-attribute-name="SecurityManager">jboss.mq:service=SecurityManager</depends><attribute name="SecurityConf">

<security><role name="guest" read="true" write="true"/><role name="publisher" read="true" write="true" create="false"/><role name="durpublisher" read="true" write="true" create="true"/>

</security></attribute>

</mbean>

<mbean code="org.jboss.mq.server.jmx.Queue"name="jboss.mq.destination:service=Queue,name=testQueue">

<depends optional-attribute-name="DestinationManager">jboss.mq:service=DestinationManager</depends><depends optional-attribute-name="SecurityManager">jboss.mq:service=SecurityManager</depends><attribute name="SecurityConf">

<security><role name="guest" read="true" write="true"/><role name="publisher" read="true" write="true" create="false"/>

</security></attribute>

</mbean></server>

<?xml version="1.0" encoding="UTF-8"?><server>

<mbean code="org.jboss.mq.server.jmx.Topic"name="jboss.mq.destination:service=Topic,name=testTopic">

<depends optional-attribute-name="DestinationManager">jboss.mq:service=DestinationManager</depends><depends optional-attribute-name="SecurityManager">jboss.mq:service=SecurityManager</depends><attribute name="SecurityConf">

<security><role name="guest" read="true" write="true"/><role name="publisher" read="true" write="true" create="false"/><role name="durpublisher" read="true" write="true" create="true"/>

</security></attribute>

</mbean>

<mbean code="org.jboss.mq.server.jmx.Queue"name="jboss.mq.destination:service=Queue,name=testQueue">

<depends optional-attribute-name="DestinationManager">jboss.mq:service=DestinationManager</depends><depends optional-attribute-name="SecurityManager">jboss.mq:service=SecurityManager</depends><attribute name="SecurityConf">

<security><role name="guest" read="true" write="true"/><role name="publisher" read="true" write="true" create="false"/>

</security></attribute>

</mbean></server>

© JBoss, Inc. 2003-2005. 44

Professional Open Source™

Message Caching

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.

Page 23: Messaging

23

© JBoss, Inc. 2003-2005. 45

Professional Open Source™

Message Softening

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 code="org.jboss.mq.server.MessageCache"name="jboss.mq:service=MessageCache">

<attribute name="HighMemoryMark">50</attribute><attribute name="MaxMemoryMark">60</attribute><attribute name="CacheStore">jboss.mq:service=PersistenceManager</attribute>

</mbean>

<mbean code="org.jboss.mq.server.MessageCache"name="jboss.mq:service=MessageCache">

<attribute name="HighMemoryMark">50</attribute><attribute name="MaxMemoryMark">60</attribute><attribute name="CacheStore">jboss.mq:service=PersistenceManager</attribute>

</mbean>

© JBoss, Inc. 2003-2005. 46

Professional Open Source™

The Persistence Manager

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

The PersistenceManager saves and restore PERSISTENT messages andthose 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.

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

Page 24: Messaging

24

© JBoss, Inc. 2003-2005. 47

Professional Open Source™

The JDBC Persistence Manager

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 code="org.jboss.mq.pm.jdbc2.PersistenceManager“name="jboss.mq:service=PersistenceManager">

<depends optional-attribute-name="ConnectionManager">jboss.jca:service=LocalTxCM,name=DefaultDS</depends>

<attribute name="SqlProperties">…

</attribute></mbean>

<mbean code="org.jboss.mq.pm.jdbc2.PersistenceManager“name="jboss.mq:service=PersistenceManager">

<depends optional-attribute-name="ConnectionManager">jboss.jca:service=LocalTxCM,name=DefaultDS</depends>

<attribute name="SqlProperties">…

</attribute></mbean>

© JBoss, Inc. 2003-2005. 48

Professional Open Source™

JDBC Persistence Manager’s SqlProperties

<attribute name="SqlProperties">BLOB_TYPE=OBJECT_BLOBINSERT_TX = INSERT INTO JMS_TRANSACTIONS (TXID) values(?)INSERT_MESSAGE = INSERT INTO JMS_MESSAGES (MESSAGEID, DESTINATION, \

MESSAGEBLOB, TXID, TXOP) VALUES(?,?,?,?,?)SELECT_ALL_UNCOMMITED_TXS = SELECT TXID FROM JMS_TRANSACTIONSSELECT_MAX_TX = SELECT MAX(TXID) FROM JMS_MESSAGESSELECT_MESSAGES_IN_DEST = SELECT MESSAGEID, MESSAGEBLOB FROM JMS_MESSAGES \

WHERE DESTINATION=?SELECT_MESSAGE = SELECT MESSAGEID, MESSAGEBLOB FROM JMS_MESSAGES \

WHERE MESSAGEID=? AND DESTINATION=?MARK_MESSAGE = UPDATE JMS_MESSAGES SET TXID=?, TXOP=? \

WHERE MESSAGEID=? AND DESTINATION=?UPDATE_MESSAGE = UPDATE JMS_MESSAGES SET MESSAGEBLOB=? \

WHERE MESSAGEID=? AND DESTINATION=?UPDATE_MARKED_MESSAGES = UPDATE JMS_MESSAGES SET TXID=?, TXOP=? WHERE TXOP=?UPDATE_MARKED_MESSAGES_WITH_TX = UPDATE JMS_MESSAGES SET TXID=?, TXOP=? \

WHERE TXOP=? AND TXID=?DELETE_MARKED_MESSAGES_WITH_TX = DELETE FROM JMS_MESSAGES WHERE TXOP=? AND \

JMS_MESSAGES.TXID IN (SELECT TXID FROM JMS_TRANSACTIONS)DELETE_TX = DELETE FROM JMS_TRANSACTIONS WHERE TXID = ?DELETE_MARKED_MESSAGES = DELETE FROM JMS_MESSAGES WHERE TXID=? AND TXOP=?DELETE_TEMPORARY_MESSAGES = DELETE FROM JMS_MESSAGES WHERE TXOP='T'DELETE_MESSAGE = DELETE FROM JMS_MESSAGES WHERE MESSAGEID=? AND DESTINATION=?CREATE_MESSAGE_TABLE = CREATE CACHED TABLE JMS_MESSAGES ( MESSAGEID INTEGER NOT NULL, \

DESTINATION VARCHAR(255) NOT NULL, TXID INTEGER, TXOP CHAR(1), \MESSAGEBLOB OBJECT, PRIMARY KEY (MESSAGEID, DESTINATION) )

CREATE_TX_TABLE = CREATE CACHED TABLE JMS_TRANSACTIONS ( TXID INTEGER, PRIMARY KEY (TXID) )CREATE_TABLES_ON_STARTUP = TRUE

</attribute>

<attribute name="SqlProperties">BLOB_TYPE=OBJECT_BLOBINSERT_TX = INSERT INTO JMS_TRANSACTIONS (TXID) values(?)INSERT_MESSAGE = INSERT INTO JMS_MESSAGES (MESSAGEID, DESTINATION, \

MESSAGEBLOB, TXID, TXOP) VALUES(?,?,?,?,?)SELECT_ALL_UNCOMMITED_TXS = SELECT TXID FROM JMS_TRANSACTIONSSELECT_MAX_TX = SELECT MAX(TXID) FROM JMS_MESSAGESSELECT_MESSAGES_IN_DEST = SELECT MESSAGEID, MESSAGEBLOB FROM JMS_MESSAGES \

WHERE DESTINATION=?SELECT_MESSAGE = SELECT MESSAGEID, MESSAGEBLOB FROM JMS_MESSAGES \

WHERE MESSAGEID=? AND DESTINATION=?MARK_MESSAGE = UPDATE JMS_MESSAGES SET TXID=?, TXOP=? \

WHERE MESSAGEID=? AND DESTINATION=?UPDATE_MESSAGE = UPDATE JMS_MESSAGES SET MESSAGEBLOB=? \

WHERE MESSAGEID=? AND DESTINATION=?UPDATE_MARKED_MESSAGES = UPDATE JMS_MESSAGES SET TXID=?, TXOP=? WHERE TXOP=?UPDATE_MARKED_MESSAGES_WITH_TX = UPDATE JMS_MESSAGES SET TXID=?, TXOP=? \

WHERE TXOP=? AND TXID=?DELETE_MARKED_MESSAGES_WITH_TX = DELETE FROM JMS_MESSAGES WHERE TXOP=? AND \

JMS_MESSAGES.TXID IN (SELECT TXID FROM JMS_TRANSACTIONS)DELETE_TX = DELETE FROM JMS_TRANSACTIONS WHERE TXID = ?DELETE_MARKED_MESSAGES = DELETE FROM JMS_MESSAGES WHERE TXID=? AND TXOP=?DELETE_TEMPORARY_MESSAGES = DELETE FROM JMS_MESSAGES WHERE TXOP='T'DELETE_MESSAGE = DELETE FROM JMS_MESSAGES WHERE MESSAGEID=? AND DESTINATION=?CREATE_MESSAGE_TABLE = CREATE CACHED TABLE JMS_MESSAGES ( MESSAGEID INTEGER NOT NULL, \

DESTINATION VARCHAR(255) NOT NULL, TXID INTEGER, TXOP CHAR(1), \MESSAGEBLOB OBJECT, PRIMARY KEY (MESSAGEID, DESTINATION) )

CREATE_TX_TABLE = CREATE CACHED TABLE JMS_TRANSACTIONS ( TXID INTEGER, PRIMARY KEY (TXID) )CREATE_TABLES_ON_STARTUP = TRUE

</attribute>

Page 25: Messaging

25

© JBoss, Inc. 2003-2005. 49

Professional Open Source™

The MDB Container

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.

JVMClientILJVMClientIL

JVM Invocation LayerSpyXAConnection

SpyConnectionConsumer

StdServerSessionPool

…..

The MDB Container

JMSContainerInvoker

MessageListenerImpl

MessageDrivenContainer

Interceptors

MessageDrivenInstancePool

YourMDB…..

StdServerSessionStdServerSession

StdServerSessionStdServerSession

StdServerSessionStdServerSession

© JBoss, Inc. 2003-2005. 50

Professional Open Source™

MDB Container Fine Tuning

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’

Other configuration/tuning options:– Configure the container interceptor chain.– Change the MDB instance pool size.

<invoker-proxy-binding>

<name>message-driven-bean</name><invoker-mbean>default</invoker-mbean><proxy-factory>org.jboss.ejb.plugins.jms.JMSContainerInvoker</proxy-factory><proxy-factory-config>

….<MinimumSize>1</MinimumSize><MaximumSize>15</MaximumSize>…

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

<invoker-proxy-binding>

<name>message-driven-bean</name><invoker-mbean>default</invoker-mbean><proxy-factory>org.jboss.ejb.plugins.jms.JMSContainerInvoker</proxy-factory><proxy-factory-config>

….<MinimumSize>1</MinimumSize><MaximumSize>15</MaximumSize>…

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

Page 26: Messaging

26

© JBoss, Inc. 2003-2005. 51

Professional Open Source™

High Availability JBossMQ

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 3Node 3 Node 2Node 2

Node 1Node 1

JBossMQJBossMQ

Shared Database

Node 3Node 3

Node 1Node 1

JBossMQJBossMQ

Shared Database

Node 2Node 2

JBossMQJBossMQ

Singleton Fail-Over

© JBoss, Inc. 2003-2005. 52

Professional Open Source™

HA JBossMQ Features

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 workonly for PERSISTENT messages!

Page 27: Messaging

27

© JBoss, Inc. 2003-2005. 53

Professional Open Source™

HA JBossMQ Deployment

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. 54

Professional Open Source™

Client-side fail-over detection

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 void connect(Context context, String topicName) throws Exception {

ConnectionFactory connectionFactory = (ConnectionFactory)context.lookup("ConnectionFactory");

connection = connectionFactory.createConnection();

connection.setExceptionListener(new FailoverListener());

Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

....connection.start();

}

(continued …)

private void connect(Context context, String topicName) throws Exception {

ConnectionFactory connectionFactory = (ConnectionFactory)context.lookup("ConnectionFactory");

connection = connectionFactory.createConnection();

connection.setExceptionListener(new FailoverListener());

Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

....connection.start();

}

(continued …)

Page 28: Messaging

28

© JBoss, Inc. 2003-2005. 55

Professional Open Source™

Client-side fail-over detection

(… continued)

private class FailoverListener implements ExceptionListener {

private static final int RETRIES = 5;

public void onException(JMSException e) {

int retries = RETRIES;

while(retries-- > 0) {

try {connection.close(); // unregisters the ExceptionListener

}catch(Exception e2) {

// I will get an Exception anyway, since the connection to the server is// broken, but disconnect() frees up resouces associated with the connection

}try {

connect(jndiContext, TOPIC_NAME);break;

}catch(Exception e2) {

e.printStackTrace();}

}}

}

(… continued)

private class FailoverListener implements ExceptionListener {

private static final int RETRIES = 5;

public void onException(JMSException e) {

int retries = RETRIES;

while(retries-- > 0) {

try {connection.close(); // unregisters the ExceptionListener

}catch(Exception e2) {

// I will get an Exception anyway, since the connection to the server is// broken, but disconnect() frees up resouces associated with the connection

}try {

connect(jndiContext, TOPIC_NAME);break;

}catch(Exception e2) {

e.printStackTrace();}

}}

}

© JBoss, Inc. 2003-2005. 56

Professional Open Source™

JBossMQ Anti-Patterns

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).

Page 29: Messaging

29

© JBoss, Inc. 2003-2005. 57

Professional Open Source™

What is next?

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.