package cn.net.intervision.fileconfig;
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: MyQueueReceiver.java
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageListener;
import javax.jms.QueueConnection;
import javax.jms.QueueSession;
import javax.jms.Session;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.BlobMessage;
public class MyQueueReceiver
{
static String localdir;
public static void main(String args[])
throws Exception
{
File ivconfig = new File("IV.config");
if(ivconfig.exists()==false){
System.out.println("未找到配置文件IV.config,请将此文件放在Reciver.exe的同目录下。");
usage();
Thread.sleep(10000);
}
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(ivconfig)));
String brokeURL = br.readLine();
String UserName = br.readLine();
String Password = br.readLine();
String Queue = br.readLine();
String LocalDir = br.readLine();
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(brokeURL);
QueueConnection con = (QueueConnection)factory.createConnection(UserName,Password);
con.setClientID("\""+Queue+"\"的接收端");
QueueSession session = con.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
javax.jms.Queue queue = session.createQueue(Queue);
MessageConsumer consumer = session.createConsumer(queue);
localdir = LocalDir;
consumer .setMessageListener(new MessageListener(){
public void onMessage(Message msg) {
BlobMessage blobmsg = (BlobMessage)msg;
String FileName = null;
String JMSTimestamp = null;
String JMSExpiration = null ;
try {
FileName = blobmsg.getStringProperty("JMSCorrelationID");
JMSExpiration = blobmsg.getStringProperty("JMSExpiration");
JMSTimestamp = blobmsg.getStringProperty("JMSTimestamp");
} catch (JMSException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String FullFileName = JMSTimestamp+"_"+JMSExpiration+"_"+FileName;
File file = new File(localdir+"/"+FullFileName );
try {
file.createNewFile();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
InputStream is = blobmsg.getInputStream();
FileOutputStream fos = new FileOutputStream(file);
int count;
byte[] buff = new byte[16 * 1024];
while((count = is.read(buff)) != -1) {
fos.write(buff, 0, count);
}
fos.close();
is.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JMSException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
private static void usage() throws IOException {
// TODO Auto-generated method stub
System.out.println("如不存在,新建IV.config文件于当前目录,");
StringBuffer sb = new StringBuffer("tcp://localhost:61616\nuser\npassword\n队列1\nd:/temp\n\n\n\n\n\n\n\n\n\n");
sb.append("注意:第一行表示连接地址,第二行为用户名,第三行密码,第四行广告队列名,第五行本地目录。首行不能为空。每行首字母不能为空。");
System.out.println(sb);
}
}