Sure - I am using the following code - it is based on the example from the
ActiveMQ in Action book

public class BlobMessageTest
{
  private static final String QUEUE_NAME = "test.blob.queue";

  private static final String brokerURI =
"tcp://localhost:61616?jms.blobTransferPolicy.uploadUrl=http://localhost:8080/test/";;

  public static void writeABlob() throws Exception
  {
    try
    {
      // String brokerURI = ActiveMQConnectionFactory.DEFAULT_BROKER_URL;
      ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(
        brokerURI);
      ActiveMQConnection connection = (ActiveMQConnection) connectionFactory
        .createConnection();
      connection.start();
      ActiveMQSession session = (ActiveMQSession) connection.createSession(
        false, Session.AUTO_ACKNOWLEDGE);
      Queue destination = session.createQueue(QUEUE_NAME);
      MessageProducer producer = session.createProducer(destination);
      URL url = new URL(
        "http://localhost:8080/test/upload.txt";);
      BlobMessage message = session
        .createBlobMessage(new File(
          "C:\\upload.txt"));
      // BlobMessage message = session.createBlobMessage(url);
      producer.send(message);
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
  }

  public static void readABlob() throws Exception
  {
    // destination of our Blob data
    FileOutputStream out = new FileOutputStream(
      "C:\\Projects\\Files_To_Process1\\blob.txt");
    // String brokerURI = ActiveMQConnectionFactory.DEFAULT_BROKER_URL;
    ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(
      brokerURI);
    ActiveMQConnection connection = (ActiveMQConnection) connectionFactory
      .createConnection();
    connection.start();
    Session session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
    Queue destination = session.createQueue(QUEUE_NAME);
    MessageConsumer consumer = session.createConsumer(destination);
    BlobMessage blobMessage = (BlobMessage) consumer.receive();
    InputStream in = blobMessage.getInputStream();
    // now write the file from ActiveMQ
    byte[] buffer = new byte[1024];
    while (true)
    {
      int bytesRead = in.read(buffer);
      if (bytesRead == -1)
      {
        break;
      }
      out.write(buffer, 0, bytesRead);
    }
    out.close();
    out.flush();
    in.close();
  }

  public static void main(String[] args)
  {
    try
    {
      writeABlob();
      readABlob();
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
  }
}




--
View this message in context: 
http://activemq.2283324.n4.nabble.com/Sending-Blob-Messages-PUT-was-not-successful-403-Forbidden-tp4661346p4661353.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Reply via email to