Why does this need to be a messaging solution?
On Thu, May 23, 2013 at 12:47 AM, luodaidong <[email protected]> wrote: > 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 > large > 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; > > /** > * 通过 ActiveMQ 发送文件的程序 > * > * @author hailiang > */ > public class StreamSender { > > /** > * @param args > * @throws JMSException > */ > public static void main(String[] args) throws JMSException { > FileInputStream in; > try { > in = new > FileInputStream("d:\\freeswitch-1.0.7.tar.gz"); > ActiveMQConnectionFactory connectionFactory = new > ActiveMQConnectionFactory( > > "tcp:// > 192.168.17.4:61616?jms.blobTransferPolicy.defaultUploadUrl=http://admin:[email protected]:8161/fileserver/ > "); > ActiveMQConnection connection = > (ActiveMQConnection) connectionFactory > .createConnection(); > connection.start(); > Session session = connection.createSession(false, > Session.AUTO_ACKNOWLEDGE); > Queue destination = > session.createQueue("stream.file"); > OutputStream out = > connection.createOutputStream(destination); > > // now write the file on to ActiveMQ > byte[] buffer = new byte[1024]; > while (true) { > int bytesRead = in.read(buffer); > if (bytesRead == -1) { > break; > } > System.out.println("sender\r\n"); > out.write(buffer, 0, bytesRead); > } > out.close(); > } catch (FileNotFoundException e) { > e.printStackTrace(); > } catch (IOException e) { > // TODO Auto-generated catch block > e.printStackTrace(); > } > > } > } > > > receiver > > package mytest.file; > > 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 { > > /** > * @param args > * @throws JMSException > */ > public static void main(String[] args) throws JMSException { > > > FileOutputStream out; > try { > out = new > FileOutputStream("e:\\tt\\sfreeswitch-1.0.7.tar.gz"); > ActiveMQConnectionFactory > connectionFactory = new > ActiveMQConnectionFactory("tcp://192.168.17.4:61616"); > ActiveMQConnection connection = > (ActiveMQConnection) > connectionFactory.createConnection(); > connection.start(); > Session session = connection.createSession(false, > Session.AUTO_ACKNOWLEDGE); > //we want be be an exclusive consumer > String exclusiveQueueName= "stream.file"; > Queue destination = > session.createQueue(exclusiveQueueName); > > InputStream in = > connection.createInputStream(destination); > > //now write the file from ActiveMQ > byte[] buffer = new byte[1024]; > while(true){ > int bytesRead; > bytesRead = > in.read(buffer); > if (bytesRead==-1){ > > System.out.println("receiver\r\n"); > break; > } > if(bytesRead>0) > out.write(buffer,0,bytesRead); > > } > out.close(); > } catch (FileNotFoundException e) { > e.printStackTrace(); > } catch (IOException e) { > // TODO Auto-generated catch block > e.printStackTrace(); > } > } > } > > > > > > -- > View this message in context: > http://activemq.2283324.n4.nabble.com/about-blobmessage-tp4667381p4667386.html > Sent from the ActiveMQ - User mailing list archive at Nabble.com. > -- *Christian Posta* http://www.christianposta.com/blog twitter: @christianposta
