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 374889F98 for ; Thu, 23 May 2013 03:52:49 +0000 (UTC) Received: (qmail 25898 invoked by uid 500); 23 May 2013 03:52:48 -0000 Delivered-To: apmail-activemq-users-archive@activemq.apache.org Received: (qmail 25391 invoked by uid 500); 23 May 2013 03:52: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 25324 invoked by uid 99); 23 May 2013 03:52:43 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 23 May 2013 03:52:43 +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 (nike.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 03:52:37 +0000 Received: from [192.168.236.139] (helo=joe.nabble.com) by joe.nabble.com with esmtp (Exim 4.72) (envelope-from ) id 1UfMZ0-000649-W0 for users@activemq.apache.org; Wed, 22 May 2013 20:51:38 -0700 Date: Wed, 22 May 2013 20:51:23 -0700 (PDT) From: luodaidong To: users@activemq.apache.org Message-ID: <1369281083925-4667381.post@n4.nabble.com> Subject: 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 use activeMQ blobmessage tranfering large file. It's OK, but the receiver can receive file only when the sender has sended the file completly. How about realtime transfer large file? where can I configure this? the test code following,where is wrong? the sender package mytest.file; =20 =20 import java.io.File; 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.swing.JFileChooser; import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.ActiveMQSession; import org.apache.activemq.BlobMessage; =20 /**=20 * =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 * =20 * @author hailiang=20 */ =20 public class FileSender { =20 =20 /**=20 * @param args=20 * @throws JMSException=20 */ =20 public static void main(String[] args) throws JMSException { =20 =09=09System.out.println("1111"); // =E9=80=89=E6=8B=A9=E6=96=87=E4=BB=B6 =20 JFileChooser fileChooser =3D new JFileChooser(); =20 fileChooser.setDialogTitle("=E9=80=89=E6=8B=A9=E6=96=87=E4=BB=B6");= =20 if (fileChooser.showOpenDialog(null) !=3D JFileChooser.APPROVE_OPTI= ON) { =20 return; =20 } =20 File file =3D fileChooser.getSelectedFile(); =20 =20 // =E8=8E=B7=E5=8F=96 ConnectionFactory =20 ConnectionFactory connectionFactory =3D new ActiveMQConnectionFactory("admin","admin" ,=20 =20 "tcp://192.168.17.4:61616?jms.blobTransferPolicy.defaultUploadUrl=3Dhttp://= admin:admin@192.168.17.4:8161/fileserver/"); =20 =20 // =E5=88=9B=E5=BB=BA Connection =20 Connection connection =3D connectionFactory.createConnection(); =20 connection.start(); =20 =20 // =E5=88=9B=E5=BB=BA Session =20 ActiveMQSession session =3D (ActiveMQSession) connection.createSession( =20 false, Session.AUTO_ACKNOWLEDGE); =20 =20 // =E5=88=9B=E5=BB=BA Destination =20 Destination destination =3D session.createQueue("File.Transport"); = =20 =20 // =E5=88=9B=E5=BB=BA Producer =20 MessageProducer producer =3D session.createProducer(destination); = =20 producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);// =E8=AE=BE= =E7=BD=AE=E4=B8=BA=E9=9D=9E=E6=8C=81=E4=B9=85=E6=80=A7 =20 // =E8=AE=BE=E7=BD=AE=E6=8C=81=E4=B9=85=E6=80=A7=E7=9A=84=E8=AF=9D= =EF=BC=8C=E6=96=87=E4=BB=B6=E4=B9=9F=E5=8F=AF=E4=BB=A5=E5=85=88=E7=BC=93=E5= =AD=98=E4=B8=8B=E6=9D=A5=EF=BC=8C=E6=8E=A5=E6=94=B6=E7=AB=AF=E7=A6=BB=E7=BA= =BF=E5=86=8D=E8=BF=9E=E6=8E=A5=E4=B9=9F=E5=8F=AF=E4=BB=A5=E6=94=B6=E5=88=B0= =E6=96=87=E4=BB=B6 =20 =20 // =E6=9E=84=E9=80=A0 BlobMessage=EF=BC=8C=E7=94=A8=E6=9D=A5=E4=BC= =A0=E8=BE=93=E6=96=87=E4=BB=B6 =20 BlobMessage blobMessage =3D session.createBlobMessage(file); =20 blobMessage.setStringProperty("FILE.NAME", file.getName()); =20 blobMessage.setLongProperty("FILE.SIZE", file.length()); =20 System.out.println("=E5=BC=80=E5=A7=8B=E5=8F=91=E9=80=81=E6=96=87= =E4=BB=B6=EF=BC=9A" + file.getName() + "=EF=BC=8C=E6=96=87=E4=BB=B6=E5=A4= =A7=E5=B0=8F=EF=BC=9A" =20 + file.length() + " =E5=AD=97=E8=8A=82"); =20 =20 // 7. =E5=8F=91=E9=80=81=E6=96=87=E4=BB=B6 =20 producer.send(blobMessage); =20 System.out.println("=E5=AE=8C=E6=88=90=E6=96=87=E4=BB=B6=E5=8F=91= =E9=80=81=EF=BC=9A" + file.getName()); =20 =20 producer.close(); =20 session.close(); =20 connection.close(); // =E4=B8=8D=E5=85=B3=E9=97=AD Connection, =E7= =A8=8B=E5=BA=8F=E5=88=99=E4=B8=8D=E9=80=80=E5=87=BA =20 } =20 } =20 the receiver package mytest.file; =20 import java.io.*; =20 import javax.jms.*; =20 import javax.jms.Message; =20 import javax.swing.*; =20 import org.apache.activemq.*; =20 =20 public class FileReciever { =20 =20 /**=20 * @param args=20 * @throws JMSException=20 */ =20 public static void main(String[] args) throws JMSException { =20 =20 // =E8=8E=B7=E5=8F=96 ConnectionFactory =20 ConnectionFactory connectionFactory =3D new ActiveMQConnectionFacto= ry( =20 "tcp://192.168.17.4:61616"); =20 =20 // =E5=88=9B=E5=BB=BA Connection =20 Connection connection =3D connectionFactory.createConnection(); =20 connection.start(); =20 =20 // =E5=88=9B=E5=BB=BA Session =20 Session session =3D connection.createSession(false, =20 Session.AUTO_ACKNOWLEDGE); =20 =20 // =E5=88=9B=E5=BB=BA Destinatione =20 Destination destination =3D session.createQueue("File.Transport"); = =20 =20 // =E5=88=9B=E5=BB=BA Consumer =20 MessageConsumer consumer =3D session.createConsumer(destination); = =20 =20 // =E6=B3=A8=E5=86=8C=E6=B6=88=E6=81=AF=E7=9B=91=E5=90=AC=E5=99=A8= =EF=BC=8C=E5=BD=93=E6=B6=88=E6=81=AF=E5=88=B0=E8=BE=BE=E6=97=B6=E8=A2=AB=E8= =A7=A6=E5=8F=91=E5=B9=B6=E5=A4=84=E7=90=86=E6=B6=88=E6=81=AF =20 consumer.setMessageListener(new MessageListener() { =20 =20 // =E7=9B=91=E5=90=AC=E5=99=A8=E4=B8=AD=E5=A4=84=E7=90=86=E6=B6= =88=E6=81=AF =20 public void onMessage(Message message) { =20 if (message instanceof BlobMessage) { =20 BlobMessage blobMessage =3D (BlobMessage) message; =20 try { =20 String fileName =3D blobMessage =20 .getStringProperty("FILE.NAME"); =20 System.out.println("=E6=96=87=E4=BB=B6=E6=8E=A5=E6= =94=B6=E8=AF=B7=E6=B1=82=E5=A4=84=E7=90=86=EF=BC=9A" + fileName + "=EF=BC= =8C=E6=96=87=E4=BB=B6=E5=A4=A7=E5=B0=8F=EF=BC=9A" =20 + blobMessage.getLongProperty("FILE.SIZE") = =20 + " =E5=AD=97=E8=8A=82"); =20 =20 JFileChooser fileChooser =3D new JFileChooser(); = =20 fileChooser.setDialogTitle("=E8=AF=B7=E6=8C=87=E5= =AE=9A=E6=96=87=E4=BB=B6=E4=BF=9D=E5=AD=98=E4=BD=8D=E7=BD=AE"); =20 fileChooser.setSelectedFile(new File(fileName)); = =20 if (fileChooser.showSaveDialog(null) =3D=3D JFileChooser.APPROVE_OPTION) { =20 File file =3D fileChooser.getSelectedFile(); = =20 OutputStream os =3D new FileOutputStream(file);= =20 =20 System.out.println("=E5=BC=80=E5=A7=8B=E6=8E=A5= =E6=94=B6=E6=96=87=E4=BB=B6=EF=BC=9A" + fileName); =20 InputStream inputStream =3D blobMessage =20 .getInputStream(); =20 =20 // =E5=86=99=E6=96=87=E4=BB=B6=EF=BC=8C=E4=BD= =A0=E4=B9=9F=E5=8F=AF=E4=BB=A5=E4=BD=BF=E7=94=A8=E5=85=B6=E4=BB=96=E6=96=B9= =E5=BC=8F =20 byte[] buff =3D new byte[256]; =20 int len =3D 0; =20 while ((len =3D inputStream.read(buff)) > 0) { = =20 os.write(buff, 0, len); =20 } =20 os.close(); =20 System.out.println("=E5=AE=8C=E6=88=90=E6=96=87= =E4=BB=B6=E6=8E=A5=E6=94=B6=EF=BC=9A" + fileName); =20 } =20 =20 } catch (Exception e) { =20 e.printStackTrace(); =20 } =20 } =20 } =20 }); =20 } =20 } =20 -- View this message in context: http://activemq.2283324.n4.nabble.com/about-b= lobmessage-tp4667381.html Sent from the ActiveMQ - User mailing list archive at Nabble.com.