jboss4.2.3 Building Oracle JMS applications

Source: Internet
Author: User
Tags jboss

First, the basic configuration

1 Add Oracle driver file, Ojdbc6.jar, cannot use less than this version of the JDBC driver, jboss-4.2.3.ga\server\default\lib

2 Increase Retrotranslator-runtime-1.2.3.jar,jboss-4.2.3.ga\server\default\lib

3 Configuring the data source

JBOSS-4.2.3.GA\SERVER\DEFAULT\DEPLOY\JMS Increase Oracle-ds.xml

4 Configuring the JMS environment for JBoss

Copy JBOSS4.2.3\DOCS\EXAMPLES\JMS under Mysql-jdbc2-service.xml to JBOSS4.2.3\SERVER\DEFAULT\DEPLOY\JMS.
Under and change the database datasourcebinding to Name=oracleds

5 Adding Oracle-jdbc-state-service.xml files

Modify the Hsqldb-jdbc-state-service file in the \JBOSS4.2.3\SERVER\DEFAULT\DEPLOY\JMS directory to Oracle-jdbc-state-service.xml,

and will <depends optional-attribute-name= "ConnectionManager" >jboss.jca:service=datasourcebinding,name=defaultds </depends>

Modify the database to use Name=oracleds to connect to your MySQL.

When the above configuration is complete, the following JMS-prefixed tables are created in Oracle data:

SELECT * from Jms_users;
SELECT * from Jms_roles;
SELECT * from Jms_messages;

Wait a minute

Second, security policy configuration

On the basis of the above configuration, continue to complete the following configuration

1. Jbossmq-destinations-service.xml Add a custom queue and reference the default security manager

Jboss-4.2.3.ga\server\default\deploy\jms\jbossmq-destinations-service.xml

<MbeanCode= "Org.jboss.mq.server.jmx.Queue"name= "Jboss.mq.destination:service=queue,name=fasqueue">         <dependsOptional-attribute-name= "Destinationmanager">Jboss.mq:service=destinationmanager</depends>         <dependsOptional-attribute-name= "SecurityManager">Jboss.mq:service=securitymanager</depends>     <attributename= "Messagecounterhistorydaylimit">-1</attribute>     <attributename= "securityconf">      <Security>        <rolename= "Guest"Read= "false"Write= "false"/>        <rolename= "publisher"Read= "true"Write= "true"Create= "false"/>        <rolename= "NOACC"Read= "false"Write= "false"Create= "false"/>        <rolename= "Aaarole"Read= "true"Write= "true"Create= "false"/>      </Security>    </attribute>    </Mbean>

2. Modify the Jbossmq-service.xml in the security domain, you can use the default "JBOSSMQ"

Jboss-4.2.3.ga\server\default\deploy\jms\jbossmq-service.xml

<MbeanCode= "Org.jboss.mq.security.SecurityManager"name= "Jboss.mq:service=securitymanager">    <attributename= "Defaultsecurityconfig">      <Security>        <rolename= "Guest"Read= "true"Write= "true"Create= "true"/>      </Security>    </attribute>    <attributename= "Securitydomain">Java:/jaas/jbossmq</attribute>    <depends>Jboss.security:service=jaassecuritymanager</depends>     <dependsOptional-attribute-name= "Nextinterceptor">Jboss.mq:service=destinationmanager</depends>  </Mbean>

3. Modify the security policy file, add a new security control policy, this article still adopts the default policy "JBOSSMQ", but need to modify the default data source

Server/default/conf/login-config.xml

<!--Security domain for JBOSSMQ -    <Application-policyname= "JBOSSMQ">       <Authentication>          <Login-moduleCode= "Org.jboss.security.auth.spi.DatabaseServerLoginModule"Flag= "Required">             <module-optionname= "Unauthenticatedidentity">Guest</module-option>             <module-optionname= "Dsjndiname">Java:/oracleds</module-option>             <module-optionname= "Principalsquery">SELECT PASSWD from Jms_users WHERE userid=?</module-option>             <module-optionname= "Rolesquery">SELECT Roleid, ' Roles ' from Jms_roles WHERE userid=?</module-option>          </Login-module>       </Authentication>    </Application-policy>

Third, the test code

Jmssender.java

 PackageCom.demo.sender;Importjava.util.Properties;Importjavax.jms.JMSException;ImportJavax.jms.Queue;Importjavax.jms.QueueConnection;Importjavax.jms.QueueConnectionFactory;ImportJavax.jms.QueueSender;Importjavax.jms.QueueSession;Importjavax.jms.Session;ImportJavax.jms.TextMessage;ImportJavax.naming.Context;ImportJavax.naming.InitialContext;Importjavax.naming.NamingException; Public classJmssender { Public Static voidMain (string[] args)throwsjmsexception, namingexception {Properties env=NewProperties (); Env.put (Context.provider_url,"127.0.0.1:1099"); Env.put (Context.initial_context_factory,"Org.jnp.interfaces.NamingContextFactory"); Env.put (Context.url_pkg_prefixes,"Org.jboss.naming:org.jnp.interfaces"); Context Context=NewInitialContext (env); Queueconnectionfactory Factory= (queueconnectionfactory) context.lookup ("ConnectionFactory"); //queueconnection queueconnection = factory.createqueueconnection ();queueconnection queueconnection= Factory.createqueueconnection ("AAA", "AAA"); Queuesession queuesession= Queueconnection.createqueuesession (false, Session.auto_acknowledge); Queue Queue= (Queue) context.lookup ("Queue/fasqueue"); TextMessage message=Queuesession.createtextmessage (); Message.settext ("Hello china! Hello, China. "); Queuesender Queuesender=Queuesession.createsender (queue);        Queuesender.send (queue, message); System.out.println ("Send message successfully!"); }}
View Code

Jmsreaderv.java

 PackageCom.demo.reader;Importjava.util.Properties;Importjavax.jms.JMSException;ImportJavax.jms.Queue;Importjavax.jms.QueueConnection;Importjavax.jms.QueueConnectionFactory;ImportJavax.jms.QueueReceiver;Importjavax.jms.QueueSession;ImportJavax.jms.TextMessage;ImportJavax.naming.Context;ImportJavax.naming.InitialContext;Importjavax.naming.NamingException; Public classJmsreader { Public Static voidMain (string[] args)throwsjmsexception, namingexception {Properties env=NewProperties (); Env.put (Context.provider_url,"Localhost:1099"); Env.put (Context.initial_context_factory,"Org.jnp.interfaces.NamingContextFactory"); Env.put (Context.url_pkg_prefixes,"Org.jboss.naming:org.jnp.interfaces"); //connecting to a serverInitialContext IC =NewInitialContext (env); //Queueconnection cs = ((queueconnectionfactory) ic.lookup ("ConnectionFactory")). Createqueueconnection ();Queueconnection CS= ((queueconnectionfactory) ic.lookup ("ConnectionFactory")). Createqueueconnection ("AAA", "AAA"); Queue Q= (Queue) ic.lookup ("Queue/fasqueue"); Queuesession QSS= Cs.createqueuesession (false, Queuesession.auto_acknowledge); QueueReceiver qr=Qss.createreceiver (q); //Start linkCs.start (); //start accepting, and then process the received messageTextMessage message =(TextMessage) qr.receive ();        System.out.println (Message.gettext ()); System.out.println ("Read message successfully");    Cs.close (); }}
View Code

jboss4.2.3 Building Oracle JMS applications

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.