dimanche 18 janvier 2009

Auto JMS resources deployement in NetBeans 6.5


Well today, according to snatch my hair during two days, I provide this trick for you.


How auto deploy a JMS resources in NetBeans 6.5
1) First step, you need to create a "sun-resources.xml" in your tree project how you can see in the picture:

declare it in "Server Resources" directory.



2) Second step examine & understand this "sun-resources.xml" file:

You can see in first the xml declaration file, and the DTD which refers to sun-resources in
application server



I'am sorry for the '<' but
it is the only solution I have found to display the '<'



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

'<'!DOCTYPE resources PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 Resource Definitions //EN" "http://www.sun.com/software/appserver/dtds/sun-resources_1_3.dtd"


the root file in this xml is allow to declare several resources in the app server for you application. After you can see (for this exemple appserver : GlassFish V2):

'<'resources>
'<'admin-object-resource enabled="true" jndi-name="jms/GesResourcesQueue"
object-type="user" res-adapter="jmsra" res-type="javax.jms.Queue">

'<'description/>

'<'property name="Name" value="PhysicalQueue"/>

'<'/admin-object-resource>

'<'admin-object-resource enabled="true" jndi-name="jms/GesResourcesTopic"
object-type="user" res-adapter="jmsra" res-type="javax.jms.Topic">

'<'description/>

'<'property name="Name" value="PhysicalTopic"/>

'<'/admin-object-resource>

In this first section you declare two admin object resource the first is a "javax.jms.Queue" (type of the administred resource), you can enabled or disabled it on server with "enabled=true/false" attribute, you need to give a jndi-name for you resource (for referenced it on the JNDI context of your server) here jndi-name="jms/GesResourcesQueue".

After you need to specify the type of this object here it's a "user" type object and to finish you need to specify the "resource-adapter" here "jmsra" that integrate this Queue to your application server, by means of the standard Java Connector Architecture (JCA).

Now this you Message Queue JMS resource adapter is plugged into your application server, an application deployed in your application server can use this Message Queue to send and receive JMS message.

And to finish you can watch the this field represent the object of the physical destination JMS managed by the Sun Java System Message Queue brokers. this Queue named here "PhysicalQueue" is the system destination,
to which the messages came to an end (timeout) and not returned are redirected


The second admin-object-resource reference a "topic" instead a "queue", note that just the jndi-name change for reference the Topic created (JNDI unique name), and the type of this resource is "javax.jms.Topic" and the physical destination is now "PhysocalTopic"

'<'connector-resource enabled="true" jndi-name="jms/GesResourcesQueueFactory"
object-type="user" pool-name="jms/GesResourcesQueueFactoryPool">

'<'description/>

'<'/connector-resource>


'<'connector-resource enabled="true" jndi-name="jms/GesResourcesTopicFactory"
object-type="user" pool-name="jms/GesResourcesTopicFactoryPool">

'<'description/>

'<'/connector-resource>




In this section a connector resource is a program object that provides an application with a connection to an EIS. To create a connector resource, specify its JNDI name and its associated connection pool.

Some many parameters back exemple: object-type & enabled and jndi-name which specify the JNDI unique name of this connector resource here "jms/GesResourcesQueueFactory", it's reference the connector linked to the factory for the "jms/GesResourcesQueue" in the application server.

The pool-name reference the connection pool to the factory which specify the max of connection, timeout, validation ... on your factory.

The second connector-resource reference a connector for a topic factory & connection pool




'<'connector-connection-pool associate-with-thread="false"
connection-creation-retry-attempts="0"
connection-creation-retry-interval-in-seconds="10"
connection-definition-name="javax.jms.QueueConnectionFactory"
connection-leak-reclaim="false" connection-leak-timeout-in-seconds="0"
fail-all-connections="false" idle-timeout-in-seconds="300"
is-connection-validation-required="false" lazy-connection-association="false"
lazy-connection-enlistment="false" match-connections="true"
max-connection-usage-count="0" max-pool-size="32"
max-wait-time-in-millis="60000" name="jms/GesResourcesQueueFactoryPool"
pool-resize-quantity="2" resource-adapter-name="jmsra" steady-pool-size="8"
validate-atmost-once-period-in-seconds="0"/>

'<'connector-connection-pool associate-with-thread="false"
connection-creation-retry-attempts="0"
connection-creation-retry-interval-in-seconds="10"
connection-definition-name="javax.jms.TopicConnectionFactory"
connection-leak-reclaim="false" connection-leak-timeout-in-seconds="0"
fail-all-connections="false" idle-timeout-in-seconds="300"
is-connection-validation-required="false" lazy-connection-association="false"
lazy-connection-enlistment="false" match-connections="true"
max-connection-usage-count="0" max-pool-size="32"
max-wait-time-in-millis="60000" name="jms/GesResourcesTopicFactoryPool"
pool-resize-quantity="2" resource-adapter-name="jmsra" steady-pool-size="8"
validate-atmost-once-period-in-seconds="0"/>



This allow you to declare a connector for connection to these pool recently created.


Parameters description:

associate-with-thread : when the same thread needs a connection, it can reuse the connection already associated with this thread

connection-creation-retry-attempts: number of attempts to create a connection. "0" value means does not include a new attempt.

connection-creation-retry-interval-in-seconds: time interval between tests/try attempt to create a connection

connection-definition-name: the type of the connection-definition will be QueueConnectionFactory/TopicConnectionFactory

connection-leak-reclaim: a connection can be reused (seen in the pool) after the time limit leakage of the connection.

connection-leak-timeout-in-seconds: timeout for leakage of the connection

fail-all-connections: to close and restore all the connections in case of failure

idle-timeout-in-seconds: maximum time that a connection from the pool can remain inactive

is-connection-validation-requirement:
allows you to validate a connection before transmitting it to a container.

lazy-connection-association:
connections are associated so lazy when an operation is performed on them.

lazy-connection-enlistment: include a resource for the transaction only if it is effectively used in a method

match-connections:
toggle correspondence connections to the pool.

max-connexion-usage-count: connections are reused by the pool during the specified number of times before being closed

max-pool-size: maximum number of connections that can be created to respond to client requests

max-wait-time-in-millis: period during which the caller waits before a notice of termination of the connection to be sent.

name: the unique JNDI name of the connections pool of the connector

pool-resize-quantity: number of connections that must be removed upon expiration of the period of inactivity in the pool.

resource-adapter-name: the name of the resource adapter for this connections pool

steady-pool-size: minimum initial connections and managed in the pool

validate-atmost-once-period-in-seconds: interval during which a connection is validated once more




Now when you deploy your app server & you application you can see in logs (for Glassfish):

ADM1041 : Evénement envoyé à l'instance :[ResourceDeployEvent -- reference-added aor/jms/GesResourcesQueue]

CORE5004 : Ressource déployée : [aor:jms/GesResourcesQueue].

ADM1041 : Evénement envoyé à l'instance :[ResourceDeployEvent -- reference-added aor/jms/GesResourcesTopic]

CORE5004 : Ressource déployée : [aor:jms/GesResourcesTopic].

ADM1041 : Evénement envoyé à l'instance :[ResourceDeployEvent -- reference-added cr/jms/GesResourcesQueueFactory]

MQJMSRA_MF1101: setAddressList:NOT setting default value=localhost

MQJMSRA_MF1101: setPassword:NOT setting default value

MQJMSRA_MF1101: setUserName:NOT setting default value=guest

CORE5004 : Ressource déployée : [cr:jms/GesResourcesQueueFactory].

ADM1041 : Evénement envoyé à l'instance :[ResourceDeployEvent -- reference-added cr/jms/GesResourcesTopicFactory]

MQJMSRA_MF1101: setAddressList:NOT setting default value=localhost

MQJMSRA_MF1101: setPassword:NOT setting default value

MQJMSRA_MF1101: setUserName:NOT setting default value=guest

CORE5004 : Ressource déployée : [cr:jms/GesResourcesTopicFactory].



This trace/shows the success of the deployment of JMS resources on your application server

1 commentaire: