Linux mq 发送xml文件,发送XML文件的ActiveMQ

Please refer the below code.

Here we will receive message simple file creation then writing bytes coming from BytesMessageObject until EOF occurs.

BytesMessage bm = (BytesMessage)topicSubscriber.receiveNoWait(); // receive(1000);

System.out.println("bm-->"+bm);

if(bm !=null){

File file = new File("D:/jms/myfie.txt"); //file created

FileOutputStream fos = new FileOutputStream(file);//create fileoutput stream

BufferedOutputStream outBuf = new BufferedOutputStream(fos);//create bufferoutputstream

int i;

while((i=bm.readInt())!=-1)//read unitil EOF means -1

{

outBuf.write(i);//write it to the file

}

System.out.println("outBuf-->"+outBuf);

System.out.println(file.isFile());

outBuf.close();//close output buffer

fos.close();//close file ouput stream

}

Here the file is opened then

Wrote in BytesMessageObject.

Sent Across the Queue

Sender code :

File f=new File("D:/Import.txt");//get file handle

System.out.println("is File "+f.isFile());

BytesMessage bm = topicSession.createBytesMessage();//create bytes message

InputStream in= new FileInputStream(f);//create input stream with file handle

BufferedInputStream inBuf= new BufferedInputStream(in);//create buffer input stream

int i;

while((i=inBuf.read())!=-1)//read file until EOF(-1) is reached{

bm.writeInt(i);//write in bytesmessage

}

System.out.println("after while");

//adding an eof

bm.writeInt(-1);//add EOF in bytes message

System.out.println("BM = "+bm);

topicPublisher.send(bm);///send the bytes message

System.out.println("sent successfully");

topicConnection.stop();//stop connection

2015-07-23 12:42:19

+0

请不要随便倾倒一些代码。解释你的代码如何实际解决问题中的问题。 –

2015-07-23 13:03:39

+0

@ekad现在回答说明 –

2015-07-24 06:27:58

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值