ActiveMq Http协议发送消息:Caused by: java.io.EOFException: input contained no data

挂机的阿洋zzZ 程序员  2017-11-15 11:33:11
报错信息:
"C:\Program Files\Java\jdk1.8.0_131\bin\java" -Didea.launcher.port=7532 "-Didea.launcher.bin.path=D:\toolsNew\idea2016\IntelliJ IDEA 2016.3.4\bin" -Dfile.encoding=UTF-8 -classpath "C:\wangyongkun\workspaceEclipse\ActiveMQTest\bin;C:\Program Files\Java\jdk1.8.0_131\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\rt.jar;C:\wangyongkun\workspaceEclipse\ActiveMQTest\lib\geronimo-j2ee-management_1.1_spec-1.0.1.jar;C:\wangyongkun\workspaceEclipse\ActiveMQTest\lib\geronimo-jms_1.1_spec-1.0.jar;C:\wangyongkun\workspaceEclipse\ActiveMQTest\lib\log4j-1.2.16.jar;C:\wangyongkun\workspaceEclipse\ActiveMQTest\lib\slf4j-api-1.5.11.jar;C:\wangyongkun\workspaceEclipse\ActiveMQTest\lib\slf4j-log4j12-1.5.11.jar;C:\wangyongkun\workspaceEclipse\ActiveMQTest\lib\httpclient-4.2.5.jar;C:\wangyongkun\workspaceEclipse\ActiveMQTest\lib\xpp3-1.1.4c.jar;C:\wangyongkun\workspaceEclipse\ActiveMQTest\lib\xstream-1.4.4.jar;C:\wangyongkun\workspaceEclipse\ActiveMQTest\lib\activemq-all-5.3.0.jar;C:\wangyongkun\workspaceEclipse\ActiveMQTest\lib\httpcore-4.2.4.jar;C:\wangyongkun\workspaceEclipse\ActiveMQTest\lib\commons-httpclient-3.1.jar;C:\wangyongkun\workspaceEclipse\ActiveMQTest\lib\commons-beanutils-1.8.3.jar;C:\wangyongkun\workspaceEclipse\ActiveMQTest\lib\commons-codec-1.6.jar;C:\wangyongkun\workspaceEclipse\ActiveMQTest\lib\commons-collections-3.2.1.jar;C:\wangyongkun\workspaceEclipse\ActiveMQTest\lib\commons-dbcp-1.4.jar;C:\wangyongkun\workspaceEclipse\ActiveMQTest\lib\commons-lang-2.6.jar;C:\wangyongkun\workspaceEclipse\ActiveMQTest\lib\commons-net-3.3.jar;C:\wangyongkun\workspaceEclipse\ActiveMQTest\lib\commons-pool-1.6.jar;D:\toolsNew\idea2016\IntelliJ IDEA 2016.3.4\lib\idea_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);
}
}

}


所用jar包:
...全文
535 2 点赞 打赏 收藏 举报
写回复
2 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
zwb19920930 2019-04-14
能不能说的详细点换那个包
  • 打赏
  • 举报
回复
问题解决: 在connection.start();时,里面的DataInputStream读取出现了问题,使用另外一个包,有单独的创建DataInputStream,换上就OK了。
  • 打赏
  • 举报
回复
相关推荐
发帖
Java
加入

4.8w+

社区成员

Java相关技术讨论
申请成为版主
帖子事件
创建了帖子
2017-11-15 11:33
社区公告
暂无公告