You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by ychawla <pr...@yahoo.com> on 2006/06/18 21:42:17 UTC
ActiveMQ Outputstream message properties
Hello All,
I am sending a large file using an Active MQ output stream. I would like to
set message properties on the messages that I am sendingout (they will be
the same for all messages for a particular file). How can i do this? Here
is my code snippet. The reason I need to set properties is because this
file will be dropped in a certain directory after it reaches the queue on
the other machine.
activeMQOutputStream =
((ActiveMQConnection)connectionFactory.createConnection()).createOutputStream(queue);
BufferedInputStream in = new BufferedInputStream(new
FileInputStream(returnFileName));
//Couldn't get this working with the buffers... the char by char
read seems fine
/*
byte[] buf = new byte[32768]; // 32k buffer
int c = 0;
do {
c = in.read(buf,0,32768);
if (c > 0) activeMQOutputStream.write(buf,0,c);
} while (c >= 0);
*/
while ((value = in.read()) != -1)
{
activeMQOutputStream.write((char)value);
}
in.close();
activeMQOutputStream.flush();
activeMQOutputStream.close();
--
View this message in context: http://www.nabble.com/ActiveMQ-Outputstream-message-properties-t1807819.html#a4926668
Sent from the ActiveMQ - User forum at Nabble.com.
Re: ActiveMQ Outputstream message properties
Posted by "rain.xk" <ra...@gmail.com>.
Hi,
I try in your way ,I can get the message property ,but I get a 0kb file.
I check the database the stream message have 3 rows, but I just receive 1
row in your way.
--
View this message in context: http://www.nabble.com/ActiveMQ-Outputstream-message-properties-tf1807819.html#a5233212
Sent from the ActiveMQ - User forum at Nabble.com.
Re: ActiveMQ Outputstream message properties
Posted by ychawla <pr...@yahoo.com>.
Again, I apologize, I have updated code at work which I did not check in so I
can not access now. This should work to read the BytesMessage. The last
message in the sequence will be, I think, a StreamMessage with a group
sequence of -1 and this will indicate to you that you are at the end of your
file and you can close the stream.
ActiveMQInputStream streamMsg = (ActiveMQInputStream
)connection.createInputStream();
ActiveMQMessage message = streamMsg.receive();
message.getStringProperty("fileName");
ByteSequence bs = ((ActiveMQBytesMessage)message).getContent();
fos.write(bs.getData());
--
View this message in context: http://www.nabble.com/ActiveMQ-Outputstream-message-properties-tf1807819.html#a5233075
Sent from the ActiveMQ - User forum at Nabble.com.
Re: ActiveMQ Outputstream message properties
Posted by "rain.xk" <ra...@gmail.com>.
Hi,
If I use this way:
ActiveMQInputStream streamMsg = (ActiveMQInputStream
)connection.createInputStream();
ActiveMQMessage message = streamMsg.receive();
message.getStringProperty("fileName");
I can get the property,but I can not get the stream message.
can you show me your whole code about the stream message with property?
--
View this message in context: http://www.nabble.com/ActiveMQ-Outputstream-message-properties-tf1807819.html#a5233013
Sent from the ActiveMQ - User forum at Nabble.com.
Re: ActiveMQ Outputstream message properties
Posted by ychawla <pr...@yahoo.com>.
I read the messages using a message driven POJO in Spring 2.0. The
ActiveMQBytesMessage extends an ActiveMQMessage so you can use the methods
available in ActiveMQMessage, such as getStringProperty, to read the
message properties. I have my code at work but I think this is an example
that might be helpful:
if (message instanceof BytesMessage) {
try {
log.debug("This is the message type:" + message.getJMSType() + "\n\n" +
message);
//HERE YOU ARE GETTING A PROPERTY
log.debug("This is the invocation property" +
message.getStringProperty("invocation") + "\n\n" + message);
messageId = ((ActiveMQBytesMessage)message).getGroupID();
ByteSequence bs = ((ActiveMQBytesMessage)message).getContent();
fos.write(bs.getData());
} catch (JMSException e) {
throw new RuntimeException(e);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
--
View this message in context: http://www.nabble.com/ActiveMQ-Outputstream-message-properties-tf1807819.html#a5232815
Sent from the ActiveMQ - User forum at Nabble.com.
Re: ActiveMQ Outputstream message properties
Posted by ychawla <pr...@yahoo.com>.
With the code sample you posted, you can probably also do something like
this... I have my code at work so I will check this out on Monday.
ActiveMQInputStream streamMsg = (ActiveMQInputStream
)connection.createInputStream();
ActiveMQMessage message = streamMsg.receive();
message.getStringProperty("fileName");
--
View this message in context: http://www.nabble.com/ActiveMQ-Outputstream-message-properties-tf1807819.html#a5232880
Sent from the ActiveMQ - User forum at Nabble.com.
Re: ActiveMQ Outputstream message properties
Posted by "rain.xk" <ra...@gmail.com>.
i receive stream message like this:
ActiveMQInputStream streamMsg = (ActiveMQInputStream
)connection.createInputStream();
FileWrite file = new FileWrite("d:\temp.rar", 0);
while ((byteread = streamMsg.read(buffer)) != -1) {
log.info("get file now======");
file.write(buffer, 0, byteread);
}
how can i get the message property?
Or I can get the stream message by another way ?
--
View this message in context: http://www.nabble.com/ActiveMQ-Outputstream-message-properties-tf1807819.html#a5232663
Sent from the ActiveMQ - User forum at Nabble.com.
Re: ActiveMQ Outputstream message properties
Posted by ychawla <pr...@yahoo.com>.
To retrieve the message, you can get the properties you set. For example, I
added an entry called 'invocation' to my map and retrieve it using
'message.getStringProperty':
invocationType = message.getStringProperty("invocation");
--
View this message in context: http://www.nabble.com/ActiveMQ-Outputstream-message-properties-tf1807819.html#a5232553
Sent from the ActiveMQ - User forum at Nabble.com.
Re: ActiveMQ Outputstream message properties
Posted by "rain.xk" <ra...@gmail.com>.
Hi,
When I receive the Message,How can I get the myMap Info?
--
View this message in context: http://www.nabble.com/ActiveMQ-Outputstream-message-properties-tf1807819.html#a5227800
Sent from the ActiveMQ - User forum at Nabble.com.
Re: ActiveMQ Outputstream message properties
Posted by ychawla <pr...@yahoo.com>.
Hi James,
I appreciate the reply. The approach you outline worked great. Here is
sample code for anyone else who might have looked at this thread:
Map myMap = new HashMap();
//TODO - We have some hardcoded JMS properties here.. probably okay
//You can put any properties in this map below that you desire
myMap.put("invocation", serviceInfoForJms.getInvocationType());
myMap.put("submitterURI", serviceInfoForJms.getSubmitterURI());
myMap.put("operatorURI", serviceInfoForJms.getOperatorURI());
activeMQOutputStream =
((ActiveMQConnection)connectionFactory.createConnection()).createOutputStream(queue,
myMap, ActiveMQMessage.DEFAULT_DELIVERY_MODE,
ActiveMQMessage.DEFAULT_PRIORITY, ActiveMQMessage.DEFAULT_TIME_TO_LIVE);
--
View this message in context: http://www.nabble.com/ActiveMQ-Outputstream-message-properties-t1807819.html#a4963715
Sent from the ActiveMQ - User forum at Nabble.com.
Re: ActiveMQ Outputstream message properties
Posted by James Strachan <ja...@gmail.com>.
The Map is the properties you want to set on the JMS message. So put
in it whatever key/value pairs you'd normally add to a JMS Message via
the setObjectProperty(key, value) method.
I've just updated the javadoc on this method to make it more explicit.
On 6/19/06, ychawla <pr...@yahoo.com> wrote:
>
> Maybe the properties can be set while creating the output stream here, line
> 62 appears to set the Properties but I can't find any documention for what
> should be in the Map properties:
>
> 056 public ActiveMQOutputStream(ActiveMQConnection connection,
> ProducerId producerId, ActiveMQDestination destination,
> 057 Map properties, int deliveryMode, int priority, long
> timeToLive) throws JMSException {
> 058 this.connection = connection;
> 059 this.deliveryMode = deliveryMode;
> 060 this.priority = priority;
> 061 this.timeToLive = timeToLive;
> 062 this.properties = properties==null ? null : new
> HashMap(properties);
> --
> View this message in context: http://www.nabble.com/ActiveMQ-Outputstream-message-properties-t1807819.html#a4929350
> Sent from the ActiveMQ - User forum at Nabble.com.
>
>
--
James
-------
http://radio.weblogs.com/0112098/
Re: ActiveMQ Outputstream message properties
Posted by ychawla <pr...@yahoo.com>.
Maybe the properties can be set while creating the output stream here, line
62 appears to set the Properties but I can't find any documention for what
should be in the Map properties:
056 public ActiveMQOutputStream(ActiveMQConnection connection,
ProducerId producerId, ActiveMQDestination destination,
057 Map properties, int deliveryMode, int priority, long
timeToLive) throws JMSException {
058 this.connection = connection;
059 this.deliveryMode = deliveryMode;
060 this.priority = priority;
061 this.timeToLive = timeToLive;
062 this.properties = properties==null ? null : new
HashMap(properties);
--
View this message in context: http://www.nabble.com/ActiveMQ-Outputstream-message-properties-t1807819.html#a4929350
Sent from the ActiveMQ - User forum at Nabble.com.
Re: ActiveMQ Outputstream message properties
Posted by ychawla <pr...@yahoo.com>.
Hello,
I looked a little at the API and it appears that the message is created here
(line 124 in flushbuffer)... I don't think there is any capabilities there
to set properties on the message. Am i mistaken or barking up the wrong
tree?
Thanks,
Yogesh
public synchronized void write(byte b[], int off, int len) throws
IOException {
104 while(len > 0) {
105 int max = Math.min(len, buffer.length-count);
106 System.arraycopy(b, off, buffer, count, max);
107
108 len -= max;
109 count += max;
110 off += max;
111
112 if (count == buffer.length) {
113 flushBuffer();
114 }
115 }
116 }
117
118 synchronized public void flush() throws IOException {
119 flushBuffer();
120 }
121
122 private void flushBuffer() throws IOException {
123 try {
124 ActiveMQBytesMessage msg = new ActiveMQBytesMessage();
125 msg.writeBytes(buffer, 0, count);
126 send(msg, false);
127 } catch (JMSException e) {
128 throw IOExceptionSupport.create(e);
129 }
130 count=0;
131 }
--
View this message in context: http://www.nabble.com/ActiveMQ-Outputstream-message-properties-t1807819.html#a4929312
Sent from the ActiveMQ - User forum at Nabble.com.