JBoss Advanced Configuration

Source: Internet
Author: User
Tags jboss

1. Configure the data source
Taking MySQL database configuration as an example, {JBOSS_HOME} is the installation directory of Jboss4.0.2.
1, find the mysql-ds.xml under {jboss_home}/docs/examples/JCA, if ms SQL Server is the mssql-ds.xml;
If it's oracle, it's oracle-ds.xml.
2, modify the mysql-ds.xml's JNDI-name, connection-URL, driver-class, user-name, password element, the following is an example
<? XML version = "1.0" encoding = "UTF-8"?>
<! -- $ ID: mysql-ds.xml, V 1.3.2.1 2004/12/01 11:46:00 schrouf exp $ -->
<! -- Datasource config for MySQL using 3.0.9 available from:
Http://www.mysql.com/downloads/api-jdbc-stable.html
-->
<Datasources>
<Local-TX-datasource>
<JNDI-Name> mysqlds </JNDI-Name>
<Connection-URL> JDBC: mysql: // 127.0.0.1: 3306/scretary </connection-URL>
<Driver-class> com. MySQL. JDBC. Driver </driver-class>
<User-name> root </user-name>
<Password> pass </password>
<Exception-sorter-class-name> org. jboss. resource. adapter. jdbc. vendor. MySQLExceptionSorter </exception-sorter-class-name>
<! -- SQL to call when connection is created
<New-connection-SQL> some arbitrary SQL </new-connection-SQL>
-->
<! -- SQL to call on an existing pooled connection when it is obtained from pool
<Check-valid-connection-SQL> some arbitrary SQL </check-valid-connection-SQL>
-->

<! -- Corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
<Metadata>
<Type-mapping> mysql </type-mapping>
</Metadata>
</Local-TX-datasource>
</Datasources>
3. Copy the modified file to {jboss_home}/Server/default/deploy and restart JBoss.
If there is no error, the startup process will output:
10:15:40, 593 info [wrapperdatasourceservice] bound connection factory for resource adapter for connectionmanager 'jboss. JCA: service = performancebinding, name = mysqlds to JNDI name' Java: mysqlds'
Open the console http: // localhost: 8080/JMX-console, and you can see the data source we Just configured under JBoss. JCA.
Name = mysqlds, service = performancebinding
Name = mysqlds, service = localtxcm
Name = mysqlds, service = managedconnectionfactory
Name = mysqlds, service = managedconnectionpool
4. Use the JNDI name "Java: mysqlds" to access the data source.

 

Private Static void getdatasource ()...{
Context CTX = NULL;
Try ...{
CTX = new initialcontext ();
} Catch (namingexception e )...{
// Todo auto-generated Catch Block
Log. Error ("initialcontext error:" + E. getmessage ());
Return;
}
Try ...{
Object OBJ = CTX. Lookup (dsjndiname );
DS = (datasource) OBJ;
} Catch (exception e )...{
Log. Error ("JNDI datasource's JNDI name" + dsjndiname + "error :"
+ E. getmessage ());
}
Return;
}

2. Configure the JMS Topic and Queue

The following example shows how to configure a JMS Topic named testTopic and a Jms Queue named testQueue.
1, open the {JBOSS_HOME}/server/default/deploy/jms/jbossmq-destinations-service.xml File
Add the following section before and after </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>

The above indicates configuring a Topic named testTopic. You can modify the name as needed.
The configuration of Queue is similar to that of Topic. Add the following section:

<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 = "MessageCounterHistoryDayLimit">-1 </attribute>
<Attribute name = "SecurityConf">
<Security>
<Role name = "guest" read = "true" write = "true"/>
<Role name = "publisher" read = "true" write = "true" create = "false"/>
<Role name = "noacc" read = "false" write = "false" create = "false"/>
</Security>
</Attribute>
</Mbean>

The configuration code above is to configure a Queue named testQueue. You can also modify the name as needed.
2. Restart Jboss. If there is no error, you can see
10:15:39, 281 INFO [testTopic] Bound to JNDI name: topic/testTopic
10:15:39, 296 INFO [testQueue] Bound to JNDI name: queue/testQueue

You can access the topic and queue objects by using the Jndi names "java: Topic/testTopic" and "java: Queue/testQueue.

 

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.