错误信息如下:
`"C:Program FilesJavajdk1.8.0_131binjava" -Didea.launcher.port=7532 "-Didea.launcher.bin.path=D:toolsNewidea2016IntelliJ IDEA 2016.3.4bin" -Dfile.encoding=UTF-8 -classpath "C:wangyongkunworkspaceEclipseActiveMQTestbin;C:Program FilesJavajdk1.8.0_131jrelibcharsets.jar;C:Program FilesJavajdk1.8.0_131jrelibdeploy.jar;C:Program FilesJavajdk1.8.0_131jrelibextaccess-bridge-64.jar;C:Program FilesJavajdk1.8.0_131jrelibextcldrdata.jar;C:Program FilesJavajdk1.8.0_131jrelibextdnsns.jar;C:Program FilesJavajdk1.8.0_131jrelibextjaccess.jar;C:Program FilesJavajdk1.8.0_131jrelibextjfxrt.jar;C:Program FilesJavajdk1.8.0_131jrelibextlocaledata.jar;C:Program FilesJavajdk1.8.0_131jrelibextnashorn.jar;C:Program FilesJavajdk1.8.0_131jrelibextsunec.jar;C:Program FilesJavajdk1.8.0_131jrelibextsunjce_provider.jar;C:Program FilesJavajdk1.8.0_131jrelibextsunmscapi.jar;C:Program FilesJavajdk1.8.0_131jrelibextsunpkcs11.jar;C:Program FilesJavajdk1.8.0_131jrelibextzipfs.jar;C:Program FilesJavajdk1.8.0_131jrelibjavaws.jar;C:Program FilesJavajdk1.8.0_131jrelibjce.jar;C:Program FilesJavajdk1.8.0_131jrelibjfr.jar;C:Program FilesJavajdk1.8.0_131jrelibjfxswt.jar;C:Program FilesJavajdk1.8.0_131jrelibjsse.jar;C:Program FilesJavajdk1.8.0_131jrelibmanagement-agent.jar;C:Program FilesJavajdk1.8.0_131jrelibplugin.jar;C:Program FilesJavajdk1.8.0_131jrelibresources.jar;C:Program FilesJavajdk1.8.0_131jrelibrt.jar;C:wangyongkunworkspaceEclipseActiveMQTestlibgeronimo-j2ee-management_1.1_spec-1.0.1.jar;C:wangyongkunworkspaceEclipseActiveMQTestlibgeronimo-jms_1.1_spec-1.0.jar;C:wangyongkunworkspaceEclipseActiveMQTestliblog4j-1.2.16.jar;C:wangyongkunworkspaceEclipseActiveMQTestlibslf4j-api-1.5.11.jar;C:wangyongkunworkspaceEclipseActiveMQTestlibslf4j-log4j12-1.5.11.jar;C:wangyongkunworkspaceEclipseActiveMQTestlibhttpclient-4.2.5.jar;C:wangyongkunworkspaceEclipseActiveMQTestlibxpp3-1.1.4c.jar;C:wangyongkunworkspaceEclipseActiveMQTestlibxstream-1.4.4.jar;C:wangyongkunworkspaceEclipseActiveMQTestlibactivemq-all-5.3.0.jar;C:wangyongkunworkspaceEclipseActiveMQTestlibhttpcore-4.2.4.jar;C:wangyongkunworkspaceEclipseActiveMQTestlibcommons-httpclient-3.1.jar;C:wangyongkunworkspaceEclipseActiveMQTestlibcommons-beanutils-1.8.3.jar;C:wangyongkunworkspaceEclipseActiveMQTestlibcommons-codec-1.6.jar;C:wangyongkunworkspaceEclipseActiveMQTestlibcommons-collections-3.2.1.jar;C:wangyongkunworkspaceEclipseActiveMQTestlibcommons-dbcp-1.4.jar;C:wangyongkunworkspaceEclipseActiveMQTestlibcommons-lang-2.6.jar;C:wangyongkunworkspaceEclipseActiveMQTestlibcommons-net-3.3.jar;C:wangyongkunworkspaceEclipseActiveMQTestlibcommons-pool-1.6.jar;D:toolsNewidea2016IntelliJ IDEA 2016.3.4libidea_rt.jar" com.intellij.rt.execution.application.AppMain com.activemq.test.SendTest
Exception in thread "ActiveMQ Transport: HTTP Reader http://10.30.101.60:61610" com.thoughtworks.xstream.io.StreamException: : input contained no data
at com.thoughtworks.xstream.io.xml.XppReader.pullNextEvent(XppReader.java:126)
at com.thoughtworks.xstream.io.xml.AbstractPullReader.readRealEvent(AbstractPullReader.java:148)
at com.thoughtworks.xstream.io.xml.AbstractPullReader.readEvent(AbstractPullReader.java:141)
at com.thoughtworks.xstream.io.xml.AbstractPullReader.move(AbstractPullReader.java:118)
at com.thoughtworks.xstream.io.xml.AbstractPullReader.moveDown(AbstractPullReader.java:103)
at com.thoughtworks.xstream.io.xml.XppReader.<init>(XppReader.java:63)
at com.thoughtworks.xstream.io.xml.AbstractXppDriver.createReader(AbstractXppDriver.java:54)
at com.thoughtworks.xstream.XStream.fromXML(XStream.java:913)
at com.thoughtworks.xstream.XStream.fromXML(XStream.java:904)
at org.apache.activemq.transport.xstream.XStreamWireFormat.unmarshalText(XStreamWireFormat.java:51)
at org.apache.activemq.transport.util.TextWireFormat.unmarshal(TextWireFormat.java:49)
at org.apache.activemq.transport.http.HttpClientTransport.run(HttpClientTransport.java:142)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.io.EOFException: input contained no data
at org.xmlpull.mxp1.MXParser.fillBuf(MXParser.java:3003)
at org.xmlpull.mxp1.MXParser.more(MXParser.java:3046)
at org.xmlpull.mxp1.MXParser.parseProlog(MXParser.java:1410)
at org.xmlpull.mxp1.MXParser.nextImpl(MXParser.java:1395)
at org.xmlpull.mxp1.MXParser.next(MXParser.java:1093)
at com.thoughtworks.xstream.io.xml.XppReader.pullNextEvent(XppReader.java:109)
... 12 more`
sctivemq版本:apache-activemq-5.9.0
activemq.xml文件:
activemq部署于Linux上:
Linux版本号:Linux ZLJK01 2.6.32-573.el6.x86_64 #1 SMP Wed Jul 1 18:23:37 EDT 2015 x86_64 x86_64 x86_64 GNU/Linux
···package com.activemq.util;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.DeliveryMode;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;
import org.apache.activemq.ActiveMQConnectionFactory;
public class SendUtil {
// Connection :JMS 客户端到JMS Provider 的连接
private Connection connection = null;
// Session: 一个发送或接收消息的线程
private Session session;
// MessageProducer:消息发送者
private MessageProducer producer;
public SendUtil(String userName, String pwd, String url, String queueName) {
// 构造ConnectionFactory实例对象,此处采用ActiveMq的实现jar
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(
userName, pwd, url);
try {
// 构造从工厂得到连接对象
connection = connectionFactory.createConnection();
// 启动
connection.start();
// 获取操作连接
session = connection.createSession(Boolean.TRUE,
Session.AUTO_ACKNOWLEDGE);
// 获取session注意参数值xingbo.xu-queue是一个服务器的queue,须在在ActiveMq的console配置
Destination destination = session.createQueue(queueName);
// 得到消息生成者【发送者】
producer = session.createProducer(destination);
// 设置不持久化,此处学习,实际根据项目决定
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
// 构造消息,此处写死,项目就是参数,或者方法获取
// sendMessage(session, producer);
// session.commit();
} catch (Exception e) {
close();
e.printStackTrace();
}
}
public void sendMessage(String message) {
try {
// 构造消息
TextMessage msg = session.createTextMessage(message);
System.out.println("发送消息:" + message);
// 发送消息到目的地方
producer.send(msg);
session.commit();
} catch (JMSException e) {
close();
e.printStackTrace();
}
}
public void close() {
try {
if (producer != null)
producer.close();
if (session != null)
session.close();
if (connection != null)
connection.close();
} catch (Throwable ignore) {
}
}
···package com.activemq.test;
import org.apache.activemq.ActiveMQConnection;
import com.activemq.util.SendUtil;
public class SendTest {
/**
* @param args
*/
public static void main(String[] args) {
String name = ActiveMQConnection.DEFAULT_USER;
String pwd = ActiveMQConnection.DEFAULT_PASSWORD;
String url = "http://10.30.101.60:61610";
SendUtil sender = new SendUtil(name, pwd, url, "FirstQueue2");
for (int i = 0; i < 10; i++) {
sender.sendMessage("message" + i);
}
}
}···
问题解决:
在connection.start();时,里面的DataInputStream读取出现了问题,使用另外一个包,有单独的创建DataInputStream,换上就OK了。
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。