Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use JMS in Jboss

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "how to use JMS in Jboss". In daily operation, I believe many people have doubts about how to use JMS in Jboss. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "how to use JMS in Jboss"! Next, please follow the editor to study!

1. Introduction

In order to create and run this example. We use two ways to do this: one is to use the Ant command, and the other is to use the JAR and JAVA basic commands. You must have the following environment variables:

W JAVA_HOME the directory where JDK1.4 is installed.

W JBOSS_DIST the directory where JBoss is installed.

You must install JDK. If you use Ant, you must install Ant. You can refer to the introduction of my previous document.

2. Overview

1) what is JMS

JMS is a Java API that allows applications to create, receive, and read messages. Programs rely on these API and need an JMS implementation interface at run time to provide management and control, which is called JMS provider, and there are now several different JMS Provider; called JbossMQ in JBoss.

2) JMS and J2EE

JMS was developed before the development of EJB and J2EE frameworks, so there is no mention of EJB or J2EE in the JMS specification.

JMS is also not covered in the first-generation versions of EJB and J2EE, up to EJB1.1, and JMS is not a required API in generating a container provider for an available Beand. The JMS interface is required in J2EE1.2, but it is not necessary to include a JMS Provider; and change it in EJB2.0 and J2EE1.3. The application server contains a JMS Provider since J2EE1. 3 EJB2.0 is required, and the following two JMS features have been added:

W A new Bean type definition, message-driven Beam (MDB), which acts as a JMS message listener and can process JMS messages asynchronously.

W JMS processing as a resource, JMD publishing (sending) from one Bean must be shared with the global transaction environment of other bean. This requires that you think of JMS as a container-managed resource, like a connection to JDBC.

3) JMS and JBoss

JBoss has supported JMS since version 2. 0. MDB has been added in 2.1. since version 2.4, JMS has been used as a transactional resource.

The architecture of JMS in JBoss is as follows:

W JMS Provider, called JbossMQ. Is part of the JBoss implementation JMS 1.0.2 specification, including optional parts such as ASF (Application Service Facvility). JbossMQ handles the same as general JMS: establishing queues (queue) or topic (title), persistence, and so on.

W MDB (Message Driven Beans)

W resource adapter.

3 、 JMS Provider

JBoss has its own JMS Provider called JbossMQ. Suitable for JMS Provider with JMS 1.0.2, and can be used in all ordinary JMS programs. To understand how JMS works in JBoss, you should first be aware of the concepts and terminology involved in JMS. The best way is to read the JMS specification. A brief introduction to JMS is given below.

1) A brief introduction to JMS

When you send a message, you cannot send it directly to the recipient who is interested in the message. Instead, you send it to a destination. Recipients interested in this message must connect to the destination, get the message, or set up a subscription at the destination.

There are two kinds of domains in JMS: topics and queues.

W A message is sent to a topics and can have multiple clients. Release with topic allows one-to-many, or many-to-many communication channels. The producer of the message is called publisher, and the recipient of the message is called subscriber.

W queue is another way to allow only one message to be delivered to one customer. A sender puts the message in the message queue, and the receiver extracts the message from the queue and gets the message, and the message disappears in the queue. After the first recipient extracts and gets the message, others can no longer get it.

In order to be able to send and receive messages, a JMS connection must be obtained. The connection is obtained using JMS Provider, and after the connection is obtained, a session (Session) is established. Then set up a publisher/sender to send messages or subscriber/receiver to receive messages.

At run time, if you use topic, then publisher or subscriber is associated with a topic, and if you use queue, sender or receiver is associated through queue.

In general, the way it works in the JMS framework is as follows:

(1) get a JNDI initialization context (Context)

(2) find a connection factory TopicConnectFactory/ QueueConnectionFactory according to the context (there are two connection factories, using the corresponding type according to the topic/queue)

(3) get a connection from the connection factory (Connect has two [TopicConnection/ QueueConnection])

(4) establish a session through connection (Session)

(5) find destination (Topic/ Queue)

(6) establish message maker (TopicPublisher/QueueSender) and consumer (TopicSubscriber/ QueueReceiver) according to session and destination.

In order to get a connection and a destination (to correlate publisher/sender or subscriber/receiver), you must use the provider-specific parameter.

Use JNDI to find the appropriate connection factory or destination, and JNDI is suitable for any JMS Provider. But the name used for the search is used by provider. Therefore, before you use JMS Provider (including JBossMQ), you must learn how to specify. Any settings in JMS Provider, such as connection features, destination used, etc., are clearly described in the Provider used.

2) configuration

When using a JMS Provider, there are three Provider-specific factors:

W get a JNDI initialization context

W the name of the connection factory used.

W. Management and naming protocols for destinations.

JBoss executes with its JNDI. For simple JMS client, configure and find the initialization context, just like any other J2EE client.

JMS-specific to constrain the JMS provider (JBossMQ) of JBoss. JbossMQ is configured through the xml file jbossmq-service.xml, which is placed under serverdefaultdeploy.

The three most basic things in a xml file:

W add a new destination

W configure users

W gets the name of the available connection factory.

(1) add new destinations

W the xml file at the destination is jbossmq-destinations-service.xml (server/../deploy) in jboss 3.x. There are already several default destinations in the file, so it's easier for you to understand how to add to the file. In the example you need a topic destination spool, so add the following statement to jbossmq-destinations-service.xml. This approach persists for a long time and does not disappear when the JBoss server is shut down.

Jboss.mq:service=DestinationManager

W another way is to manage the interface through JMX HTML. Access through http://localhost:8080/jmx-console. Find the connection to service=DestinationManager under jboss.mq. Then set up in createTopic () or createQueue (), the destination established by this method is temporary, and as the server begins to exist, when the JBoss server restarts, the dynamically established destination will not exist. All destinations in JbossMQ have a prefix of destination type. The prefix is topic for topic and queue for queues. For example, to find a testTopic destination, you need to find the name "topic/testTopic".

In this method, there are two methods for createTopic () or createQueue (): one has two parameters, and the other has one parameter. The two parameters are the established destination name and the JNDI name. A parameter is only the destination name, and the default for the JNDI name is: [destination type (topic/queue)] / destination name.

What we use here is the first method. Modify the jbossmq-destinations-service.xml file directly.

(2) manage users

It is possible to associate a connection with a user in JMS, but unfortunately there is no explicit way to restrict access to JbossMQ or access to a particular destination to a given user. In order to give most roles, there is no need to create users in JbossMQ unless you want to have a persistent topic subscriber. In this example, the user is a must.

Users can add it directly in the file jbossmq-state.xml (server/../conf). You can also use the JMX HTML administration interface to add (jboss.mq- > service=StateManager- > addUser ()).

Jacky

Jacky

DurableSubscriberExample

>

(3) connection factory

JBossMQ includes several different connection factories for topic and queue, each with its own characteristics. When looking up a connection factory through JNDI, you need to know the name of the connection factory. All available connection factories and their properties, names will be in the file jbossmq-service.xml.

There are three types of connection factories that depend on the following communication protocols:

OIL

Fast two-way scoket communication protocol. It is the default.

UIL

More than one socket protocol can be used when accessing through a firewall, or when the client cannot correctly find the IP address of the server.

RMI

The earliest agreement was stable, but slow.

JVM

A new connection factory type has been added after JBoss 2.4. Socket is not required, but can be used when the client and JbossMQ use the same virtual machine.

In later versions of JBoss2.4.1, the connection factory uses the same name for both topic- and queue- destinations. The following table lists the JMS connection factories in JBoss:

Destination type JNDI name connection factory type

Topic/Queue java:/ConnectionFactory JVM

Topic/Queue java:/XAConnectionFactory JVM supports XA transactions

Topic/Queue RMIConnectionFactory RMI

Topic/Queue RMIXAConnectionFactory RMI supports XA transactions

Topic/Queue ConnectionFactory OIL

Topic/Queue XAConnectionFactory OIL supports XA transactions

Topic/Queue UILConnectionFactory UIL

Topic/Queue UILXAConnectionFactory UIL supports XA transactions

3) Advanced JMS configuration in JBoss

The above paragraph mainly describes the basic configuration work implemented with JbossMQ. Other JMS configurations are described in this paragraph.

(1) JMS persistence management

JMS persistence Management (PM) is responsible for storing messages and marking messages as persistent, ensuring that messages are not lost in the event of a server failure, and allowing persistent messages to be recovered. Persistent JMS messages can be accomplished in different ways. Each method has its own advantages and disadvantages:

Advantages and disadvantages of PM name

File is relatively stable and slow.

The speed of Rollinglogged is relatively fast. This method is relatively new and needs to be improved in some areas.

JDBC must have JDBC for stability and measurability.

Logged is fast Log files grow without bound, memory management problems during recovery

The default persistence message management in JBoss is File persistence management. It can be changed, but only for a JMS

Server has one and only one persistence management configuration. So your jboss.mq in the JBoss management interface? >

Service=PersistenceManager just saw one.

The configuration file for persistence management is jbossmq-service.xml. Under server..deploy.

In order to let you understand the various methods of persistence management, I will show you how to configure them one by one.

W File persistence Management

The concept of File persistence management is to create a file for each persistent message. Not all message persistence methods can be used, but it is relatively stable.

File persistence management acts as a default persistence management when JBoss is released. If you open the jbossmq-service.xml file, you will see the following XML:

Db/jbossmq/file

Jboss.mq:service=MessageCache

When setting up the Mbean configuration, File persistence management allows you to specify the following properties:

DataDircetory is the path where persistent messages are stored, and the generated data files are placed in this directory.

W set Rollinglogged persistence management

Rollinglogged persistence management is a relatively new method of persistent message management, because it uses log files to persist multiple messages, so when creating a file, you do not need a lot of Icano.

Define Rollinglogged persistence management:

Db/jbossmq/file

Jboss.mq:service=MessageCache

The path where the DataDirctory stores persistent messages in Rollinglogged persistence management, and the generated data files are placed in this directory.

W set JDBC persistence management

JDBC persistence management uses database tables to store messages. A JBoss-configured data source is required to access the database. Refer to the contents in the jbossmq-service.xml file for details.

W set Logged persistence management

Logged persistence management is an early one and is not recommended in later versions of JBoss2.4.1. Now there is a better way.

4. Give an example

When we are clear about the future, let's use JBoss to implement an example to deepen our understanding of JBoss and JMS.

In the above description, we know that there are three basic things to do to explicitly use JMS provider: configure the JNDI initialization context, the name of the connection factory, and the name of the destination to use.

The best thing about writing a product is not affected by provider-specific, so that the code can be easily portable between different JMS provider. Instead of focusing on developing products, this example explains how to use JbossMQ to work.

1) initialize context

One way to configure JNDI is through the properties file jndi.properties. Using the correct value in this file and including its path in classpath makes it easier to get the correct initialization context.

The jndi.properties file is as follows:

Java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory

Java.naming.provider.url=localhost:1099

Java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces

Make the path where the file is placed as part of your classpath. If you use this method, the code is relatively simple when initializing the context: Context context = new IntialContext (); 1

W in some scenarios, you may need to configure JNDI; manually, for example, when the environment in the running class file is configured with an initialization context, but it is not the context you want to use, you need to configure a context manually. Several property values set in the hash table, and use this hash table to instantiate a context. Define the syntax:

Hashtable props = new Hashtable ()

Props.put (Context.INITIAL_CONTEXT_FACTORY

"org.jnp.interfaces.NamingContextFactory")

Props.put (Context.PROVIDER_URL, "localhost:1099")

Props.put ("java.naming.rmi.security.manager", "yes")

Props.put (Context.URL_PKG_PREFIXES, "org.jboss.naming")

2) find the connection factory

Once you have your own context, you need to find a connection factory. To find it, use an available name. The code to find the connection factory is as follows:

For a topic destination

TopicConnectionFactory topicFactory = (TopicConnectionFactory) context.lookup ("ConnectionFactory")

Queue destination:

QueueConnectionFactory queueFactory = (QueueConnectionFactory) context.lookup ("ConnectionFactory")

3) establish a connection and session

After we have a connection factory, establish a connection and establish a session in this connection.

For topic, the code is as follows:

/ / establish a connection

TopicConnection = topicFactory.createTopicConnection ()

/ / establish a session

TopicSession = topicConnection.createTopicSession (false, / / No transaction is required

Session.AUTO_ACKNOLEDGE / / automatically receives the receipt of the message.

);

For queue, the code is as follows:

/ / establish a connection

QueueConnection = queueFactory.createQueueConnection ()

/ / establish a session

QueueSession = queueConnection .createQueueSession (false, / / No transaction is required

Session.AUTO_ACKNOLEDGE / / automatically receives the receipt of the message.

);

Configure whether to invoke a transaction when a session is established

In a transaction Session, when a transaction is committed, it is automatically received, and if the transaction is rolled back, all consumed messages will be re-sent.

In a non-transactional Session, if a transaction is not invoked, there are three ways to deliver messages:

Session.AUTO_ACKNOWLEDGE: when the receive method invoked by the client returns successfully, or when the MessageListenser successfully processes the message, session will automatically receive the receipt of the message.

Session.CLIENT_ACKNOWLEDGE: the client receives the message by calling the acknowledge method of the message. Reception occurs at the session layer. When a consumed message is received, all messages that have been consumed by the session are automatically received. For example, if the consumer of the message consumes 10 messages and then receives 15 delivered messages, the receipts for the first 10 messages will be received in these 15 messages.

Session.DUPS_ACKNOWLEDGE: instructs session to receive messages slowly.

4) find the destination

Now let's introduce the creation of publishes/sends or subscribles/receives messages.

The following code is listed to find a destination:

Find a testTopic destination for topic

Topic topic = (Topic) context.lookup ("topic/testTopic")

Find a testQueue destination for queue

Queue queue= (Queue) context.lookup ("queue/testQueue")

Note: the prefix topic/ (queue/) of JbossM is usually preceded by the name topic (queue).

In JMS, when the client plays each role, such as publisher for topic, subscriber for queue or sender and receiver for queue, each has its own different class inheritance and different functions.

5) create a message maker Message Producer (topic publisher/ queue sender)

The message maker is an object created by session, whose main job is to send messages to the destination.

For a topic, you need to create a TopicPublisher through TopicSession. The code is as follows:

TopicPublisher topicPublisher = TopicSession.createPublisher (topic)

For a queue, you need to create a QueueSender through QueueSession. The code is as follows:

QueuePublisher queuePublisher = queueSession.createSender (queue)

6) message sending

Create a TestMessage and publish it, code:

TextMessage message = topicSession.createTestMessage ()

Message.setText (msg)

TopicPublishe.publish (topic, message)

Create a TestMessage and send it, code:

TextMessage message = queueSession.createTestMessage ()

Message.setText (msg)

QueueSender.send (queue, message)

7) the following is a completed topic publisher code with the file name HelloPublisher.java:

Import javax.naming.Context

Import javax.naming.InitialContext

Import javax.naming.NamingException

Import javax.jms.TopicConnectionFactory

Import javax.jms.TopicConnection

Import javax.jms.TopicSession

Import javax.jms.TopicPublisher

Import javax.jms.Topic

Import javax.jms.TextMessage

Import javax.jms.Session

Import javax.jms.JMSException

Import java.util.Hashtable

Public class HelloPublisher {

TopicConnection topicConnection

TopicSession topicSession

TopicPublisher topicPublisher

Topic topic

Public HelloPublisher (String factoryJNDI, String topicJNDI)

Throws JMSException, NamingException {

Hashtable props=new Hashtable ()

Props.put (Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory")

Props.put (Context.PROVIDER_URL, "localhost:1099")

Props.put ("java.naming.rmi.security.manager", "yes")

Props.put (Context.URL_PKG_PREFIXES, "org.jboss.naming")

Context context = new InitialContext (props)

TopicConnectionFactory topicFactory =

(TopicConnectionFactory) context.lookup (factoryJNDI)

TopicConnection = topicFactory.createTopicConnection ()

TopicSession = topicConnection.createTopicSession (false, Session.AUTO_ACKNOWLEDGE)

Topic = (Topic) context.lookup (topicJNDI)

TopicPublisher = topicSession.createPublisher (topic)

}

Public void publish (String msg) throws JMSException {

TextMessage message = topicSession.createTextMessage ()

Message.setText (msg)

TopicPublisher.publish (topic, message)

}

Public void close () throws JMSException {

TopicSession.close ()

TopicConnection.close ()

}

Public static void main (String [] args) {

Try {

HelloPublisher publisher = new HelloPublisher (

"ConnectionFactory", "topic/testTopic")

For (int I = 1; I

< 11; i++) { String msg = "Hello World no. " + i; System.out.println("Publishing message: " + msg); publisher.publish(msg); } publisher.close(); } catch(Exception ex) { System.err.println( "An exception occurred while testing HelloPublisher25: " + ex); ex.printStackTrace(); } } } 我们知道,使用JMS不仅能发送(send)/发布(publish)消息,也能获得(send)/发布(publish)的消息。在时间方式有良种方法来做: w 同步(Synchronously):需要手工的去得到消息,为了得到一个消息客户机调用方法得到消息,直到消息到达或在规定的时间内没有到达而超时。我们在例子中没有说明这部分,大家可以实验一下。 w 异步(Asynchronously):你需要定义一个消息监听器(MessageListener),实现该接口。当消息达到时,JMS provider通过调用该对象的 onMessage方法来传递消息。 从原则来将,topic和queue都是异步的,但是在这两种目的地中有不同的类和方法。首先,必须定义一个MessageListener接口。 8) 建立一个MessageListener 在建立了你需要的subscriber/receiver,并且登记了监听器后。就可以调用连接的start方法得到JMS provider 发送到的消息了。如果在登记监听器之前调用start方法,很可能会丢失消息。 public void onMessage(Message m) { try { String msg = ((TextMessage)m).getText(); System.out.println("HelloSubscriber got message: " + msg); } catch(JMSException ex) { System.err.println("Could not get text message: " + ex); ex.printStackTrace(); } } 9) 建立消息消费者 对于topic来将: //建立一个订阅者 topicSubscriber = topicSession.createSubscriber(topic); //设置消息监听器, topicSubscriber.setMessageListener(this) //连接开始 topicConnection.start(); 对于queue来将: //建立一个订阅者 queueReceiver = queueSession.createReceiver(queue); //设置消息监听器, queueReceiver .setMessageListener(this) //连接开始 queueConnection.start(); 10) 完整的代码,放在文件HelloSubscriber.java中,如下: import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import javax.jms.TopicConnectionFactory; import javax.jms.TopicConnection; import javax.jms.TopicSession; import javax.jms.TopicSubscriber; import javax.jms.Topic; import javax.jms.Message; import javax.jms.TextMessage; import javax.jms.Session; import javax.jms.MessageListener; import javax.jms.JMSException; public class HelloSubscriber implements MessageListener { TopicConnection topicConnection; TopicSession topicSession; TopicSubscriber topicSubscriber; Topic topic; public HelloSubscriber(String factoryJNDI, String topicJNDI) throws JMSException, NamingException { Context context = new InitialContext(); TopicConnectionFactory topicFactory = (TopicConnectionFactory)context.lookup(factoryJNDI); topicConnection = topicFactory.createTopicConnection(); topicSession = topicConnection.createTopicSession( false, Session.AUTO_ACKNOWLEDGE); topic = (Topic)context.lookup(topicJNDI); topicSubscriber = topicSession.createSubscriber(topic); topicSubscriber.setMessageListener(this); System.out.println( "HelloSubscriber subscribed to topic: " + topicJNDI); topicConnection.start(); } public void onMessage(Message m) { try { String msg = ((TextMessage)m).getText(); System.out.println("HelloSubscriber got message: " + msg); } catch(JMSException ex) { System.err.println("Could not get text message: " + ex); ex.printStackTrace(); } } public void close() throws JMSException { topicSession.close(); topicConnection.close(); } public static void main(String[] args) { try { HelloSubscriber subscriber = new HelloSubscriber( "TopicConnectionFactory", "topic/testTopic"); } catch(Exception ex) { System.err.println( "An exception occurred while testing HelloSubscriber: " + ex); ex.printStackTrace(); } } } 11) 编辑、运行程序 直接使用命令(java) w 开启命令操作符。设置classpath : set classpath=C:jboss-3.0.6_tomcat-4.1.18clientjbossall-client.jar;C:jboss-3.0.6_tomcat-4.1.18clientjboss-j2ee.jar;C:jboss-3.0.6_tomcat-4.1.18clientjnp-client.jar;C:jboss-3.0.6_tomcat-4.1.18clientlog4j.jar;. w 首先运行订阅消息端:java HelloSubscriber w 再开启另外一个命令窗口设置classpath : set classpath=C:jboss-3.0.6_tomcat-4.1.18clientjbossall-client.jar;C:jboss-3.0.6_tomcat-4.1.18clientjboss-j2ee.jar;C:jboss-3.0.6_tomcat-4.1.18clientjnp-client.jar;C:jboss-3.0.6_tomcat-4.1.18clientlog4j.jar;. w 运行发布消息端:java HelloPublisher 5、补充 在最后我们解释JBoss-specific特性:如何用代码来管理目的地。JBoss各个版本可能不同,但是差别不大。我使用的是jboss3.0.6。 实现这个目的有两种不同的方法,依赖于是否代码是在和JBoss同样的虚拟机还是独立独立的。它们都包括调用一个通过service=DestinationManager 登记的JMX Bean。这个Mbean 有四个方法来管理目的地:createTopic(),createQueue(),destroyTopic(),destroyQueue()。 在代码中实现管理目的地在影射怎样调用MBean有不同的地方。如果程序虚拟机和Mbean服务器一样,可以直接调用。 建立一个topic 目的地的代码如下: MBeanServer server = (MBeanServer) MBeanServerFactory.findMBeanServer(null).iterator().next(); server.invoke(new ObjectName("JBossMQ", "service", "DestinationManager"), method, new Object[] { "myTopic" }, new String[] { "java.lang.String" }); 如果程序和Mbean服务器的虚拟机不同,需要通过一个JMX adapter。一个JMX adapter是一个HTML GUI。用程序通过URL来调用Mbean。代码如下: import java.io.InputStream; import java.net.URL; import java.net.HttpURLConnection; import javax.management.MBeanServerFactory; import javax.management.MBeanServer; import javax.management.ObjectName; import javax.jms.Topic; import javax.jms.Queue; public class DestinationHelper { static final String HOST = "localhost"; static final int PORT = 8080; static final String BASE_URL_ARG = "/jmx-console/HtmlAdaptor?"; public static void createDestination(Class type, String name) throws Exception { String method = null; if (type == Topic.class) { method = "createTopic"; } else if (type == Queue.class) { method = "createQueue";} invoke(method, name); } public static void destroyDestination(Class type, String name) throws Exception { String method = null; if (type == Topic.class) { method = "destroyTopic"; } else if (type == Queue.class) { method = "destroyQueue";} invoke(method, name); } protected static void invoke(String method, String destName) throws Exception { try { MBeanServer server = (MBeanServer) MBeanServerFactory.findMBeanServer(null).iterator().next(); invokeViaMBean(method, destName); }catch(Exception ex) { invokeViaUrl(method, destName);} } protected static void invokeViaUrl(String method, String destName) throws Exception { String action = "action=invokeOp&methodIndex=6&name=jboss.mq%3Aservice%3DDestinationManager&arg0=" + destName; String arg = BASE_URL_ARG + action; URL url = new URL("http", HOST, PORT, arg); HttpURLConnection con = (HttpURLConnection)url.openConnection(); con.connect(); InputStream is = con.getInputStream(); java.io.ByteArrayOutputStream os = new java.io.ByteArrayOutputStream(); byte[] buff = new byte[1024]; for(;;) { int size = is.read( buff ); if (size == -1 ) { break; } os.write(buff, 0, size); } os.flush(); if (con.getResponseCode() != HttpURLConnection.HTTP_OK ) { throw new Exception ("Could not invoke url: " + con.getResponseMessage() ); } else { System.out.println("Invoked URL: " + method + " for destination " + destName + "got resonse: " + os.toString()); } } protected static void invokeViaMBean(String method, String destName) throws Exception { MBeanServer server = (MBeanServer)MBeanServerFactory.findMBeanServer(null).iterator().next(); server.invoke(new ObjectName("JBossMQ", "service", "DestinationManager"), method, new Object[] { destName }, new String[] { "java.lang.String" }); } public static void main(String[] args) { try { if (args.length >

0) {

DestroyDestination (Topic.class, "myCreated")

} else {

CreateDestination (Topic.class, "myCreated")

}

} catch (Exception ex) {

System.out.println ("Error in administering destination:" + ex)

Ex.printStackTrace ()

}

}

}

Edit commands:

Javac-classpath jbossMust4.1.18clientjbossallmurmclient.jarmit.Cluxx.jarbothing.1.18libjbossMohamjmx.jarten. DestinationHelper.java

Run command

Java-classpath jbossMust4.1.18clientjbossallmurmclient.jarmit.Cluxx.jarbothing.1.18libjbossMohamjmx.jarten. DestinationHelper

Check that there is name=myCreated,service=Topic in the jboss.mq.destination under http://localhost:8080/jmx-console after running.

It shows that you built it successfully. When JBoss shuts down and restarts. The destination will no longer exist.

At this point, the study on "how to use JMS in Jboss" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report