Return-Path: X-Original-To: apmail-activemq-users-archive@www.apache.org Delivered-To: apmail-activemq-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D39A8909C for ; Thu, 23 May 2013 07:48:46 +0000 (UTC) Received: (qmail 23833 invoked by uid 500); 23 May 2013 07:48:46 -0000 Delivered-To: apmail-activemq-users-archive@activemq.apache.org Received: (qmail 23666 invoked by uid 500); 23 May 2013 07:48:46 -0000 Mailing-List: contact users-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@activemq.apache.org Delivered-To: mailing list users@activemq.apache.org Received: (qmail 23544 invoked by uid 99); 23 May 2013 07:48:40 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 23 May 2013 07:48:40 +0000 X-ASF-Spam-Status: No, hits=2.2 required=5.0 tests=SPF_FAIL,URI_HEX X-Spam-Check-By: apache.org Received-SPF: error (athena.apache.org: encountered temporary error during SPF processing of domain of luodaidong@sina.com) Received: from [216.139.250.139] (HELO joe.nabble.com) (216.139.250.139) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 23 May 2013 07:48:36 +0000 Received: from [192.168.236.139] (helo=joe.nabble.com) by joe.nabble.com with esmtp (Exim 4.72) (envelope-from ) id 1UfQFF-0000Av-VQ for users@activemq.apache.org; Thu, 23 May 2013 00:47:29 -0700 Date: Thu, 23 May 2013 00:47:14 -0700 (PDT) From: luodaidong To: users@activemq.apache.org Message-ID: <1369295234955-4667386.post@n4.nabble.com> In-Reply-To: <51d0ae39.b3ea.13ed038c480.Coremail.suonayi2006@163.com> References: <1369281083925-4667381.post@n4.nabble.com> <14d15e1.5c68.13ecf9be97a.Coremail.suonayi2006@163.com> <1369292094154-4667384.post@n4.nabble.com> <51d0ae39.b3ea.13ed038c480.Coremail.suonayi2006@163.com> Subject: Re: Re:Re: Re:about blobmessage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org I am newer for ActiveMQ, I use following code for streaming file.but every time the receiver just receive 768K, and then stop there. But the sender is still send data. I don't know why? I also saw someone discuss large file with ActiveMQ, He said use BlobMessage was better than Streams,But BlobMessage why isn't support realtime transfer? Realtime transfer for larg= e file maybe better in P2P . sender package mytest.file; import org.apache.activemq.ActiveMQConnection; import org.apache.activemq.ActiveMQConnectionFactory; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import javax.jms.Queue; import javax.jms.Session; import javax.jms.JMSException; /** * =E9=80=9A=E8=BF=87 ActiveMQ =E5=8F=91=E9=80=81=E6=96=87=E4=BB=B6=E7=9A= =84=E7=A8=8B=E5=BA=8F *=20 * @author hailiang */ public class StreamSender { =09/** =09 * @param args =09 * @throws JMSException =09 */ =09public static void main(String[] args) throws JMSException { =09=09FileInputStream in; =09=09try { =09=09=09in =3D new FileInputStream("d:\\freeswitch-1.0.7.tar.gz"); =09=09=09ActiveMQConnectionFactory connectionFactory =3D new ActiveMQConnectionFactory( =09=09=09=09 "tcp://192.168.17.4:61616?jms.blobTransferPolicy.defaultUploadUrl=3Dhttp://= admin:admin@192.168.17.4:8161/fileserver/"); =09=09=09ActiveMQConnection connection =3D (ActiveMQConnection) connectionF= actory =09=09=09=09=09.createConnection(); =09=09=09connection.start(); =09=09=09Session session =3D connection.createSession(false, =09=09=09=09=09Session.AUTO_ACKNOWLEDGE); =09=09=09Queue destination =3D session.createQueue("stream.file"); =09=09=09OutputStream out =3D connection.createOutputStream(destination); =09=09=09// now write the file on to ActiveMQ =09=09=09byte[] buffer =3D new byte[1024]; =09=09=09while (true) { =09=09=09=09int bytesRead =3D in.read(buffer); =09=09=09=09if (bytesRead =3D=3D -1) { =09=09=09=09=09break; =09=09=09=09} =09=09=09=09System.out.println("sender\r\n"); =09=09=09=09out.write(buffer, 0, bytesRead); =09=09=09} =09=09=09out.close(); =09=09} catch (FileNotFoundException e) { =09=09=09e.printStackTrace(); =09=09} catch (IOException e) { =09=09=09// TODO Auto-generated catch block =09=09=09e.printStackTrace(); =09=09} =09} } receiver package mytest.file; =20 import org.apache.activemq.ActiveMQConnection; import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.BlobMessage; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import javax.jms.Connection; import javax.jms.ConnectionFactory; import javax.jms.Destination; import javax.jms.JMSException; import javax.jms.Message; import javax.jms.MessageConsumer; import javax.jms.MessageListener; import javax.jms.Queue; import javax.jms.Session; import javax.swing.JFileChooser; public class StreamReceiver { =20 =09 =20 /**=20 * @param args=20 * @throws JMSException=20 */ =20 public static void main(String[] args) throws JMSException { =20 =20 =20 =09FileOutputStream out; =09=09=09try { =09=09=09=09out =3D new FileOutputStream("e:\\tt\\sfreeswitch-1.0.7.tar.gz"= ); =09=09=09=09ActiveMQConnectionFactory connectionFactory =3D new ActiveMQConnectionFactory("tcp://192.168.17.4:61616"); =09=09 ActiveMQConnection connection =3D (ActiveMQConnection) connectionFactory.createConnection(); =09=09 connection.start(); =09=09 Session session =3D connection.createSession(false, Session.AUTO_ACKNOWLEDGE); =09=09 //we want be be an exclusive consumer =09=09 String exclusiveQueueName=3D "stream.file"; =09=09 Queue destination =3D session.createQueue(exclusiveQueueName)= ; =09=09 =20 =09=09 InputStream in =3D connection.createInputStream(destination); =09=09 =20 =09=09 //now write the file from ActiveMQ =09=09 byte[] buffer =3D new byte[1024]; =09=09 while(true){ =09=09 int bytesRead; =09=09=09=09=09=09bytesRead =3D in.read(buffer); =09=09=09=09=09=09 if (bytesRead=3D=3D-1){ =09=09=09=09=09=09=09 System.out.println("receiver\r\n"); =09=09=09=09 break; =09=09=09=09 } =09=09=09=09=09=09 if(bytesRead>0) =09=09=09=09 out.write(buffer,0,bytesRead); =09=09=09=09 =20 =09=09=09=09 } =09=09=09=09 out.close(); =09=09 } catch (FileNotFoundException e) { =09=09=09=09=09e.printStackTrace(); =09=09=09=09} catch (IOException e) { =09=09=09=09=09// TODO Auto-generated catch block =09=09=09=09=09e.printStackTrace(); =09=09=09=09} } =20 } =20 -- View this message in context: http://activemq.2283324.n4.nabble.com/about-b= lobmessage-tp4667381p4667386.html Sent from the ActiveMQ - User mailing list archive at Nabble.com.