jboss 5到jboss 7 jms
我在同一台机器上运行jboss5和jboss7,所以我更改了端口nosjboss5-4040和jboss7-8080。我需要从JBoss5向JBoss7发送一条消息。我读了一篇文章,声明,必须使用JMS桥jboss 5到jboss 7 jms,jboss,jms,jboss7.x,jboss5.x,Jboss,Jms,Jboss7.x,Jboss5.x,我在同一台机器上运行jboss5和jboss7,所以我更改了端口nosjboss5-4040和jboss7-8080。我需要从JBoss5向JBoss7发送一条消息。我读了一篇文章,声明,必须使用JMS桥 https://community.jboss.org/wiki/BridgeJMSMessagesFromAS5ToAS7 我在JBoss5中创建了一个队列,并通过独立程序向队列发送消息 import java.io.Console; import java.util.Properties
https://community.jboss.org/wiki/BridgeJMSMessagesFromAS5ToAS7
我在JBoss5中创建了一个队列,并通过独立程序向队列发送消息
import java.io.Console;
import java.util.Properties;
import javax.jms.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class sender {
String url_;
String name_;
Connection conn = null;
Session session = null;
Queue queue = null;
public sender(String url, String name) throws JMSException,
NamingException {
url_ = url;
name_ = name;
this.initializeSender();
}
private void initializeSender() throws JMSException, NamingException {
Properties props = new Properties();
props.setProperty("java.naming.factory.initial",
"org.jnp.interfaces.NamingContextFactory");
props.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming");
props.setProperty("java.naming.provider.url", "jnp://localhost:1099");
Context context = new InitialContext(props);
ConnectionFactory cf = (ConnectionFactory) context
.lookup("java:/ConnectionFactory");
conn = cf.createConnection();
session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
queue = (Queue) context.lookup(name_);
conn.start();
}
public void send(String text) throws JMSException, NamingException {
// Send a text msg
MessageProducer producer = session.createProducer(queue);
TextMessage tm = session.createTextMessage(text);
producer.send(tm);
producer.close();
}
public void disconnect() throws JMSException {
if (conn != null) {
conn.stop();
}
if (session != null) {
session.close();
}
if (conn != null) {
conn.close();
}
}
public String getTopicName() {
return name_;
}
public String getTopicURL() {
return url_;
}
public static void main(String args[]) throws Exception {
sender sender = new sender("remote://localhost:4447", "BalaQueue");
sender.send("My Message");
sender.disconnect();
}
}
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Properties;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.naming.Context;
import javax.naming.InitialContext;
public class QSender {
public static void main(String[] args) {
new QSender().send();
}
public void send() {
BufferedReader reader = new BufferedReader(new InputStreamReader(
System.in));
try {
// Strings for JNDI names
String factoryName = "jms/RemoteConnectionFactory";
String queueName = "jms/queue/ram";
// Create an initial context.
Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jboss.naming.remote.client.InitialContextFactory");
props.put(Context.PROVIDER_URL, "remote://localhost:4447");
props.put(Context.SECURITY_PRINCIPAL, "ramguest");
props.put(Context.SECURITY_CREDENTIALS, "password");
InitialContext context = new InitialContext(props);
QueueConnectionFactory factory = (QueueConnectionFactory) context
.lookup(factoryName);
Queue queue = (Queue) context.lookup(queueName);
context.close();
// Create JMS objects
QueueConnection connection = factory.createQueueConnection(
"ramguest", "password");
QueueSession session = connection.createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);
QueueSender sender = session.createSender(queue);
System.out.println("Enter message to send or 'quit' to quit.");
String messageText = null;
while (true) {
messageText = reader.readLine();
if ("quit".equalsIgnoreCase(messageText)) {
break;
}
TextMessage message = session.createTextMessage(messageText);
sender.send(message);
}
// Exit
reader.close();
System.out.println("Exiting...");
connection.close();
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
}
我在JBoss7中创建了一个队列,并通过独立程序向队列发送消息
import java.io.Console;
import java.util.Properties;
import javax.jms.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class sender {
String url_;
String name_;
Connection conn = null;
Session session = null;
Queue queue = null;
public sender(String url, String name) throws JMSException,
NamingException {
url_ = url;
name_ = name;
this.initializeSender();
}
private void initializeSender() throws JMSException, NamingException {
Properties props = new Properties();
props.setProperty("java.naming.factory.initial",
"org.jnp.interfaces.NamingContextFactory");
props.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming");
props.setProperty("java.naming.provider.url", "jnp://localhost:1099");
Context context = new InitialContext(props);
ConnectionFactory cf = (ConnectionFactory) context
.lookup("java:/ConnectionFactory");
conn = cf.createConnection();
session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
queue = (Queue) context.lookup(name_);
conn.start();
}
public void send(String text) throws JMSException, NamingException {
// Send a text msg
MessageProducer producer = session.createProducer(queue);
TextMessage tm = session.createTextMessage(text);
producer.send(tm);
producer.close();
}
public void disconnect() throws JMSException {
if (conn != null) {
conn.stop();
}
if (session != null) {
session.close();
}
if (conn != null) {
conn.close();
}
}
public String getTopicName() {
return name_;
}
public String getTopicURL() {
return url_;
}
public static void main(String args[]) throws Exception {
sender sender = new sender("remote://localhost:4447", "BalaQueue");
sender.send("My Message");
sender.disconnect();
}
}
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Properties;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.naming.Context;
import javax.naming.InitialContext;
public class QSender {
public static void main(String[] args) {
new QSender().send();
}
public void send() {
BufferedReader reader = new BufferedReader(new InputStreamReader(
System.in));
try {
// Strings for JNDI names
String factoryName = "jms/RemoteConnectionFactory";
String queueName = "jms/queue/ram";
// Create an initial context.
Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jboss.naming.remote.client.InitialContextFactory");
props.put(Context.PROVIDER_URL, "remote://localhost:4447");
props.put(Context.SECURITY_PRINCIPAL, "ramguest");
props.put(Context.SECURITY_CREDENTIALS, "password");
InitialContext context = new InitialContext(props);
QueueConnectionFactory factory = (QueueConnectionFactory) context
.lookup(factoryName);
Queue queue = (Queue) context.lookup(queueName);
context.close();
// Create JMS objects
QueueConnection connection = factory.createQueueConnection(
"ramguest", "password");
QueueSession session = connection.createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);
QueueSender sender = session.createSender(queue);
System.out.println("Enter message to send or 'quit' to quit.");
String messageText = null;
while (true) {
messageText = reader.readLine();
if ("quit".equalsIgnoreCase(messageText)) {
break;
}
TextMessage message = session.createTextMessage(messageText);
sender.send(message);
}
// Exit
reader.close();
System.out.println("Exiting...");
connection.close();
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
}
和我的网桥文件jboss-service.xml
<server>
<loader-repository>com.example:archive=unique-archive-name
<loader-repository-config>java2ParentDelegation=false</loader-repository-config>
</loader-repository> <!-- AS7 JMS Provider -->
<mbean code="org.jboss.jms.jndi.JMSProviderLoader" name="jboss.messaging:service=JMSProviderLoader,name=RemoteJBossMQProvider"> <attribute name="ProviderName">RemoteXAConnectionFactory</attribute>
<attribute name="ProviderAdapterClass">org.jboss.jms.jndi.JNDIProviderAdapter</attribute>
<attribute name="FactoryRef">jms/RemoteConnectionFactory</attribute>
<attribute name="QueueFactoryRef">jms/RemoteConnectionFactory</attribute>
<attribute name="TopicFactoryRef">jms/RemoteConnectionFactory</attribute>
<attribute name="Properties"> java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.provider.url=remote://localhost:4447
java.naming.security.principal=ramguest
java.naming.security.credentials=password
</attribute>
</mbean>
<mbean code="org.jboss.jms.server.bridge.BridgeService" name="jboss.jms:service=Bridge,name=LegayBridgeSend" xmbean-dd="xmdesc/Bridge-xmbean.xml">
<depends optional-attribute-name="SourceProviderLoader">jboss.messaging:service=JMSProviderLoader,name=JMSProvider</depends>
<depends optional-attribute-name="TargetProviderLoader">jboss.messaging:service=JMSProviderLoader,name=RemoteJBossMQProvider</depends>
<attribute name="SourceDestinationLookup">BalaQueue</attribute>
<attribute name="TargetDestinationLookup">java:jboss/exported/jms/queue/ram</attribute>
<attribute name="QualityOfServiceMode">1</attribute>
<attribute name="MaxBatchSize">1</attribute>
<attribute name="MaxBatchTime">-1</attribute>
<attribute name="FailureRetryInterval">10000</attribute>
<attribute name="MaxRetries">-1</attribute>
<attribute name="AddMessageIDInHeader">false</attribute>
<attribute name="TargetUsername">ramguest</attribute>
<attribute name="TargetPassword">password</attribute>
</mbean>
</server>
有谁能指导我吗…JBOSS 7不支持JNP,请使用JBOSS远程处理
<attribute name="Properties">
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.provider.url=remote://localhost:4447
java.naming.security.principal=ramguest
java.naming.security.credentials=password
</attribute>
到
使用RESTWeb服务要容易得多。RestEeasy的实现正如它的名字所暗示的那样简单。下面有几个示例,说明如何建立rest服务以及如何在JBoss7 quickstarter项目集中调用它。相信在jBoss 5上做同样的事情不会太难。我应该只按照要求使用JMS。在两台服务器上添加传出和传入队列,让发送方rest客户端从传出队列读取消息,将消息发布到另一台服务器的web服务,该服务会将消息添加到传入队列,然后反之亦然。这将重新创建jms网桥,同时保持两台服务器与人类可读的传输机制解耦。在jboss-service.xml中,我添加了SourceDestinationLookup和TargetDestinationLookup。这些是传入和传出队列。但现在上述错误已经解决,并引发一些新错误javax.naming.NamingException:无法创建远程连接[根异常是java.util.ServiceConfigurationError:org.xnio.XnioProvider:Provider org.xnio.nio.NioXnioProvider无法实例化:java.lang.NoClassDefFoundError:无法初始化类org.xnio.NioXnioProvider]org.xnio.nio.NioXnioProvider类在类路径中也可用
org.jboss.naming.remote.client.InitialContextFactory