ActiveMQ http 连接被拒绝
ActiveMQ http connection refused
我正在尝试通过 http 将我的 java 客户端应用程序连接到 ActiveMQ,但不断收到错误消息:
Failed to perform GET on: http://localhost:8080 as response was: Connection refused: connect
为什么我连接这个连接有效:tcp://localhost:61616
activemq.xml
<broker>
...
<transportConnectors>
<transportConnector name="openwire" uri="tcp://0.0.0.0:61616?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="http" uri="http://0.0.0.0:8080"/>
</transportConnectors>
...
</broker>
jndi.properties 在我的 Java 客户端程序中:
java.naming.factory.initial = org.apache.activemq.jndi.ActiveMQInitialContextFactory
#java.naming.provider.url = tcp://localhost:61616
java.naming.provider.url = http://localhost:8080
connectionFactoryNames = connectionFactory, queueConnectionFactory, topicConnectionFactry
queue.testQueue = testQueue
Java 客户
package be.jmshub.jmsremotejndiproducer;
import javax.jms.JMSException;
import javax.jms.Connection;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.Message;
import javax.jms.Queue;
import javax.jms.QueueConnectionFactory;
import javax.naming.Context;
import javax.naming.InitialContext;
public class Producer {
public static void main(String[] args) throws JMSException {
System.out.println("JMS REMOTE PRODUCER: start");
try {
// create a new intial context, which loads from jndi.properties file
Context ctx = new InitialContext();
QueueConnectionFactory factory = (QueueConnectionFactory) ctx.lookup("connectionFactory");
Connection connection = factory.createConnection();
Queue queue = (javax.jms.Queue) ctx.lookup("testQueue");
Session session = connection.createSession(false,Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(queue);
System.out.println("JMS REMOTE PRODUCER: connected");
int count = 0;
for (int i = 0; i < 5; i++) {
String messageText = "This is message " + (i + 1);
Message message = session.createTextMessage(messageText);
System.out.println("JMS REMOTE PRODUCER: sending - " + messageText);
producer.send(message);
count += 1;
}
System.out.println("JMS REMOTE PRODUCER: total messages sent: " + count);
// Clean up
session.close();
connection.close();
} catch (Exception ex) {
System.out.println("JMS REMOTE PRODUCER: EXCEPTION:" + ex.toString());
}
System.out.println("JMS REMOTE PRODUCER: finished");
}
}
这适用于 tcp://localhost:61616 但不适用于 http://localhost:8080
谁能帮我把这东西弄起来 运行?
在下面找到一个精简的示例来启动代理。您的 Producer
运行没有任何问题。
activemq.xml
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:amq="http://activemq.apache.org/schema/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">
<broker xmlns="http://activemq.apache.org/schema/core" start="false">
<transportConnectors>
<transportConnector name="openwire" uri="tcp://0.0.0.0:0?maximumConnections=1000"/>
<transportConnector name="http" uri="http://0.0.0.0:8080"/>
</transportConnectors>
</broker>
</beans>
Broker.java
package be.jmshub.jmsremotejndiproducer;
import org.apache.activemq.broker.BrokerFactory;
import org.apache.activemq.broker.BrokerService;
public class Broker {
public static void main(String[] args) throws Exception {
BrokerService broker = BrokerFactory.createBroker("xbean:foo.xml");
broker.setPersistent(false);
broker.start();
broker.waitUntilStarted();
}
}
我正在尝试通过 http 将我的 java 客户端应用程序连接到 ActiveMQ,但不断收到错误消息:
Failed to perform GET on: http://localhost:8080 as response was: Connection refused: connect
为什么我连接这个连接有效:tcp://localhost:61616
activemq.xml
<broker>
...
<transportConnectors>
<transportConnector name="openwire" uri="tcp://0.0.0.0:61616?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="http" uri="http://0.0.0.0:8080"/>
</transportConnectors>
...
</broker>
jndi.properties 在我的 Java 客户端程序中:
java.naming.factory.initial = org.apache.activemq.jndi.ActiveMQInitialContextFactory
#java.naming.provider.url = tcp://localhost:61616
java.naming.provider.url = http://localhost:8080
connectionFactoryNames = connectionFactory, queueConnectionFactory, topicConnectionFactry
queue.testQueue = testQueue
Java 客户
package be.jmshub.jmsremotejndiproducer;
import javax.jms.JMSException;
import javax.jms.Connection;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.Message;
import javax.jms.Queue;
import javax.jms.QueueConnectionFactory;
import javax.naming.Context;
import javax.naming.InitialContext;
public class Producer {
public static void main(String[] args) throws JMSException {
System.out.println("JMS REMOTE PRODUCER: start");
try {
// create a new intial context, which loads from jndi.properties file
Context ctx = new InitialContext();
QueueConnectionFactory factory = (QueueConnectionFactory) ctx.lookup("connectionFactory");
Connection connection = factory.createConnection();
Queue queue = (javax.jms.Queue) ctx.lookup("testQueue");
Session session = connection.createSession(false,Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(queue);
System.out.println("JMS REMOTE PRODUCER: connected");
int count = 0;
for (int i = 0; i < 5; i++) {
String messageText = "This is message " + (i + 1);
Message message = session.createTextMessage(messageText);
System.out.println("JMS REMOTE PRODUCER: sending - " + messageText);
producer.send(message);
count += 1;
}
System.out.println("JMS REMOTE PRODUCER: total messages sent: " + count);
// Clean up
session.close();
connection.close();
} catch (Exception ex) {
System.out.println("JMS REMOTE PRODUCER: EXCEPTION:" + ex.toString());
}
System.out.println("JMS REMOTE PRODUCER: finished");
}
}
这适用于 tcp://localhost:61616 但不适用于 http://localhost:8080
谁能帮我把这东西弄起来 运行?
在下面找到一个精简的示例来启动代理。您的 Producer
运行没有任何问题。
activemq.xml
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:amq="http://activemq.apache.org/schema/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">
<broker xmlns="http://activemq.apache.org/schema/core" start="false">
<transportConnectors>
<transportConnector name="openwire" uri="tcp://0.0.0.0:0?maximumConnections=1000"/>
<transportConnector name="http" uri="http://0.0.0.0:8080"/>
</transportConnectors>
</broker>
</beans>
Broker.java
package be.jmshub.jmsremotejndiproducer;
import org.apache.activemq.broker.BrokerFactory;
import org.apache.activemq.broker.BrokerService;
public class Broker {
public static void main(String[] args) throws Exception {
BrokerService broker = BrokerFactory.createBroker("xbean:foo.xml");
broker.setPersistent(false);
broker.start();
broker.waitUntilStarted();
}
}