ActiveMQ Connection timed out问题

你们的风哥哥 2017-02-14 05:28:10
public void start(BundleContext context) throws Exception {
controller =new ServerController(PLUGIN_NAME);
jmsConsumer=(JMSConsumer) controller.getJMSObject(false);

MultiThreadMessageListener mtml = new MultiThreadMessageListener(10, new MessageHandler() {
@Override
public void handle(Message message, BundleContext context) {
System.out.println("文件抓取主MQ处理程序。。。");
BlobMessage blobMsg = (BlobMessage) message;//获取调用远程执行的访问信息
InputStream inputStream=null;
FileOutputStream fos = null;
Map<String, Object> map = new HashMap<String, Object>();//放置发送参数的map
JMSProducer producer=(JMSProducer) controller.getJMSObject(true);
String runSql="";//返回给主MQ入库的日志sql
String task_id="";//任务ID
File file = null;
String rName = "";
String needCallBack = "0";//是否需要回调 默认0不需要,1需要
String base="";//基线文件的名称
String lastRname = "";//上次成功抓取的文件名称
String is_first = "";//是否为第一次抓取
String catchType = "";//文件抓取类型
String catch_result = "";
String time="";
String needCompare = "";
String catch_save_path="";//文件存放路径
String fileLastCatchTime = "";
try {
System.out.println("blobMsg:"+blobMsg.toString());
rName=blobMsg.getStringProperty("FILE.RNAME");//抓取文件保存到服务器时候的真实名称
System.out.println("rName:"+rName);
catchType=blobMsg.getStringProperty("FILE.TYPE");//文件抓取类型
catch_save_path=blobMsg.getStringProperty("CATCH.SAVE.PATH");//抓取文件保存到服务器时候的路径
task_id=blobMsg.getStringProperty("TASKID");//获取任务ID
System.out.println("task_id:"+task_id);
is_first=blobMsg.getStringProperty("ISFIRST");
fileLastCatchTime = blobMsg.getStringProperty("FILE.LAST.CATCH.TIME");//文件的上次抓取时间
time=blobMsg.getStringProperty("TIME");
catch_result=blobMsg.getStringProperty("CATCH.RESULT");
base = blobMsg.getStringProperty("BASE");
lastRname = blobMsg.getStringProperty("LASTRNAME");
needCallBack = blobMsg.getStringProperty("NEEDCALLBACK");
needCompare = blobMsg.getStringProperty("NEEDCOMPARE");
try {
inputStream = blobMsg.getInputStream();
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("文件抓取端流长度:"+inputStream.available());
try {
File dir = new File("fileCatchTemp");
if(!dir.exists()){
Boolean tempDirFlag=dir.mkdirs();
if(tempDirFlag){
System.out.println("进入文件抓取主MQ端。。。,生成临时目录["+dir.getPath()+"]成功!!!");
}else{
System.out.println("进入文件抓取主MQ端。。。,生成临时目录["+dir.getPath()+"]失败!!!");
runSql=" UPDATE itil_file_catch_task t SET t.steps=CONCAT(t.steps,'-主MQ生成临时目录["+dir.getPath().replace("\\", "\\\\")+"]失败!!!-结束'),t.modify_time='"+sdf.format(new Date())+"',run_status=2 WHERE t.task_id='"+task_id+"' ";
return ;
}
}
int len = -1;
file = new File(dir,rName);
fos = new FileOutputStream(file);
byte[] b = new byte[1024];
while((len = inputStream.read(b)) != -1){
fos.write(b, 0, len);
}
fos.close();
inputStream.close();
try {
((ActiveMQBlobMessage)blobMsg).deleteFile();//注意处理完后需要手工删除服务器端文件;
} catch (Exception e) {
System.out.println("删除文件抓取main端【"+PLUGIN_NAME+"】mq文件异常。。。");
}
if(!file.exists()){
runSql=" UPDATE itil_file_catch_task t SET t.steps=CONCAT(t.steps,'-主MQ中转生成文件失败-结束'),t.modify_time='"+sdf.format(new Date())+"',run_status=2 WHERE t.task_id='"+task_id+"' ";
}else {
runSql=" UPDATE itil_file_catch_task t SET t.steps=CONCAT(t.steps,'-抓取文件中转mq接收完毕,上传至web段'),t.modify_time=date_format(now(),'%Y-%c-%d %H:%i:%s'),t.run_status='1' WHERE t.task_id='"+task_id+"' ";//
if("1".equals(catchType)){//是否上传到代理机 1文件抓取到代理机,2文件抓取到项目服务器端
map.put("TASKID", task_id);
map.put("FILE.RNAME", rName);
map.put("FILE.TYPE", catchType);
map.put("CATCH.SAVE.PATH", catch_save_path);
if ("1".equals(needCallBack) && null != needCallBack) {
map.put("LASTRNAME", lastRname);
map.put("BASE", base);
map.put("TASKID", task_id);
map.put("NEEDCALLBACK", needCallBack);
map.put("ISFIRST", is_first);
map.put("CATCH.RESULT", catch_result);
map.put("TIME", time);
map.put("FILE.LAST.CATCH.TIME", fileLastCatchTime);
if ("1".equals(needCompare)&& null != needCompare) {
producer.send("fileCatchCompareQueue", map, null);
System.out.println("对调走去对比。");
}else {
System.out.println("回调走去web。");
producer.send("FileCatchWebQueue", map, file);
}
}else {
System.out.println("走去web。");
producer.send("FileCatchWebQueue", map, file);
}
}
file.delete();
}
} catch (IOException e) {
runSql=" UPDATE itil_file_catch_task t SET t.steps=CONCAT(t.steps,'-文件抓取FILE_CATCH_main_server_ds_1.0插件出现异常'),t.modify_time=date_format(now(),'%Y-%c-%d %H:%i:%s'),t.run_status='2' WHERE t.task_id='"+task_id+"' ";//出现异常时候插入的sql信息
e.printStackTrace();
} finally {
map=new HashMap<String, Object>();
map.put("runSql", runSql);
System.out.println("中转端入库主MQ的sql::"+runSql);
producer.send(CommonUtil.getValueFromConfigFile("main.mq.url"),"TaskStatusMainQueue", map, null);//agent端发送入库信息给Proxy二级代理端,Proxy二级代理再把消息发送给主MQ入库、
file.delete();
try {
//注意处理完后需要手工删除服务器端文件 不然mq的目录中会越来越大
URL url =blobMsg.getURL();
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("DELETE");
connection.connect();
connection.disconnect();
} catch (IOException | JMSException e) {
e.printStackTrace();
}
}
} catch (Exception e) {
System.out.println("------snc_file_catch_main_server have a exception------");
e.printStackTrace();
}finally{
try {
if (inputStream != null) {
inputStream.close();
inputStream = null;
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}, context);
jmsConsumer.setMessageListener(mtml, "FileCatchMainQueue");//代理机器端监听客户端返回的文件消息队列名称,然后用ftp客户端传送给web端服务器
jmsConsumer.start();
}
适用osgi开发karaf插件监控ActiveMQ 的队列信息处理消息,在inputStream = blobMsg.getInputStream();从mq的blobMsg中获取文件流,提示java.net.ConnectException: Connection timed out
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:337)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:198)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:180)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
at java.net.Socket.connect(Socket.java:579)
at java.net.Socket.connect(Socket.java:528)
at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:388)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:483)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:213)
at sun.net.www.http.HttpClient.New(HttpClient.java:300)
at sun.net.www.http.HttpClient.New(HttpClient.java:316)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:992)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:928)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:846)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1296)
at java.net.URL.openStream(URL.java:1035)
at org.apache.activemq.blob.DefaultBlobDownloadStrategy.getInputStream(DefaultBlobDownloadStrategy.java:41)
at org.apache.activemq.blob.BlobDownloader.getInputStream(BlobDownloader.java:38)
at org.apache.activemq.command.ActiveMQBlobMessage.getInputStream(ActiveMQBlobMessage.java:132)
at snc_file_catch_main_server.Activator$1.handle(Activator.java:86)
at framework.MultiThreadMessageListener$1.run(MultiThreadMessageListener.java:53)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
------snc_file_catch_main_server have a exception------
java.lang.NullPointerException
at snc_file_catch_main_server.Activator$1.handle(Activator.java:90)
at framework.MultiThreadMessageListener$1.run(MultiThreadMessageListener.java:53)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
链接超时,但是mq的/activemq/webapps/fileserver的目录下面存在客户端发送过来的文件。但是本服务器的内网无问题,外网发送来的消息就会提示这种错误,有没有哪位大神能告知下咋么处理?
...全文
502 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
抓个包看超时在那块。

50,545

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧