|
Hi,
Is it possible to create a custom DataFormat to translate a message into a BlobMessage? I'd basically like to do something like the following: from("file:a") .unmarshal().custom("convertToBlob") .to("activemq:someQueue"); My thought was to create a new BlobMessage and replace the exchange: exchange.setOut(blobMessage); I know that BlobMessages are unique to ActiveMQ and handle things differently. I've been trying to do it but am currently stumbling on getting a Session object that I can call createBlobMessage() on. I can do what I need to using a Processor but if I could do it with a custom DataFormat it would make it so much more elegant. Any ideas? Brent |
|
Hi Brent,
> Is it possible to create a custom DataFormat to translate a message into a > BlobMessage? Sure it is. a) Create you data format implementing org.apache.camel.spi.DataFormat interface. b) Add ActiveMQConnectionFactory as your DataFormat member (you will need it to create session used to create BlobMessage) c) Implement marshal/unmarshal methods in your data format. d) Add it to your route. The resulting route could look like: DataFormat blobDataFormat = new BlobDataFormat(activeMQConnectionFactory); from("direct:binary").unmarshall(blobDataFormat).to(...) from("direct:blob").marshall(blobDataFormat).to(...) However I'm not sure how ActiveMQ component handles BlobMessages passed to it, so I can't tell you if your data format will work well with existing Camel ActiveMQ support. Best regards. -- Henryk Konsek http://henryk-konsek.blogspot.com |
|
Hello,
An alternative would be to implement your own message converter and add it to the activemq uri. See the jms component page. You will then be handed the session and I think this will save you alot of work. Best regards Pontus Den 2 aug 2012 08:37 skrev "Henryk Konsek" <[hidden email]>: > Hi Brent, > > > Is it possible to create a custom DataFormat to translate a message into > a > > BlobMessage? > > Sure it is. > > a) Create you data format implementing org.apache.camel.spi.DataFormat > interface. > b) Add ActiveMQConnectionFactory as your DataFormat member (you will > need it to create session used to create BlobMessage) > c) Implement marshal/unmarshal methods in your data format. > d) Add it to your route. > > The resulting route could look like: > > DataFormat blobDataFormat = new BlobDataFormat(activeMQConnectionFactory); > from("direct:binary").unmarshall(blobDataFormat).to(...) > from("direct:blob").marshall(blobDataFormat).to(...) > > However I'm not sure how ActiveMQ component handles BlobMessages > passed to it, so I can't tell you if your data format will work well > with existing Camel ActiveMQ support. > > Best regards. > > -- > Henryk Konsek > http://henryk-konsek.blogspot.com > |
|
> An alternative would be to implement your own message converter and add it
> to the activemq uri. Yeah, although creating BlobDataFormat for ActiveMQ is technically possible I'm not sure whether it is the best choice to achieve your (i.e. Brent's) goal. But I'll need to take a closer look at how Blobs are handled by ActiveMQ component. -- Henryk Konsek http://henryk-konsek.blogspot.com |
|
This post was updated on .
In reply to this post by hekonsek
Thanks for all the suggestions.
I've been trying to create a DataFormat to handle this. I'm stuck trying to integrate an ActiveMQ ActiveMQBlobMessage with the org.apache.camel.Exchange class working with org.apache.camel.Message's. You can't typecast one into the other. Here's my current unmarshal method: public Object unmarshal(Exchange exchange, InputStream stream) throws Exception { ActiveMQConnection connection; ActiveMQSession session; ActiveMQBlobMessage blobMessage; connection = (ActiveMQConnection) activeMQConnectionFactory.createConnection(); connection.start(); session = (ActiveMQSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE); blobMessage = (ActiveMQBlobMessage) session.createBlobMessage(stream); blobMessage.setMessageId(new MessageId(exchange.getIn().getMessageId())); // Get the data uploaded to the ActiveMQ fileserver blobMessage.getBlobUploader().upload(blobMessage); // org.apache.camel.Exchange is a Camel object expecting a org.apache.camel.Message in the Out. // BlobMessage is an ActiveMQ org.apache.activemq.command.ActiveMQBlobMessage. // This line doesn't work. They don't cast. // exchange.setOut(blobMessage); // And this was a sad attempt at trying to get around it. // DefaultMessage camelMessage = new DefaultMessage(); // camelMessage.setExchange(exchange); // camelMessage.setBody(blobMessage, org.apache.activemq.command.Message.class); // camelMessage.setMessageId(blobMessage.getMessageId().toString()); // exchange.setOut(camelMessage); // kinda by-passes things. exchange.setOut((JmsMessage)(BlobMessage)blobMessage); // ((JmsMessage)exchange.getOut()).setJmsMessage(blobMessage); return blobMessage; } When the setOut() is made I get the following exception. exchange.setOut((JmsMessage)(BlobMessage)blobMessage) = Type mismatch Can't assign org.apache.activemq.command.ActiveMQBlobMessage to org.apache.camel.Message When working with BlobMessages sent normally (via a producer.send()) I am able to retrieve the BlobMessage this way: if (! (((JmsMessage) message).getJmsMessage() instanceof BlobMessage)) { throw new CdsMsgException("Error processing batch message: Expected a BlobMessage"); } BlobMessage blobMessage = (BlobMessage) ((JmsMessage) message).getJmsMessage(); But I'm at a loss as to how to change the Message to a BlobMessage inside of a DataFormat. I assume I'm missing something fairly trivial. Thanks, Brent |
|
Hello,
Sorry for repeating myself but you should really have a look at doing this in a message converter. First you will not have to cast it to a exchange. And second you will then be handed the same session that is used to create the producer in the component. So you will participate in the same unit of work. Which I doubt is true if you create your own connection/session. But I am currently travelling so I can not test this. //Pontus Send from my phone Den 3 aug 2012 00:14 skrev "brenthale" <[hidden email]>: > Thanks for all the suggestions. > > I've been trying to create a DataFormat to handle this. I'm stuck trying > to > integrate an ActiveMQ ActiveMQBlobMessage with the > org.apache.camel.Exchange > class working with org.apache.camel.Message's. You can't typecast one into > the other. > > Here's my current unmarshal method: > > public Object unmarshal(Exchange exchange, InputStream stream) throws > Exception { > ActiveMQConnection connection; > ActiveMQSession session; > > ActiveMQBlobMessage blobMessage; > > connection = (ActiveMQConnection) > activeMQConnectionFactory.createConnection(); > connection.start(); > > session = (ActiveMQSession) connection.createSession(false, > Session.AUTO_ACKNOWLEDGE); > > blobMessage = (ActiveMQBlobMessage) session.createBlobMessage(stream); > blobMessage.setMessageId(new > MessageId(exchange.getIn().getMessageId())); > > // Get the data uploaded to the ActiveMQ fileserver > blobMessage.getBlobUploader().upload(blobMessage); > > // org.apache.camel.Exchange is a Camel object expecting a > org.apache.camel.Message in the Out. > // BlobMessage is an ActiveMQ > org.apache.activemq.command.ActiveMQBlobMessage. > // This line doesn't work. They don't cast. > // exchange.setOut(blobMessage); > > // And this was a sad attempt at trying to get around it. > // DefaultMessage camelMessage = new DefaultMessage(); > // camelMessage.setExchange(exchange); > // camelMessage.setBody(blobMessage, > org.apache.activemq.command.Message.class); > // camelMessage.setMessageId(blobMessage.getMessageId().toString()); > // exchange.setOut(camelMessage); // kinda by-passes things. > > // if (! (((JmsMessage) message).getJmsMessage() instanceof > BlobMessage)) > { > exchange.setOut((JmsMessage)(BlobMessage)blobMessage); > // ((JmsMessage)exchange.getOut()).setJmsMessage(blobMessage); > > return blobMessage; > } > > > When the setOut() is made I get the following exception. > > exchange.setOut((JmsMessage)(BlobMessage)blobMessage) = Type mismatch Can't > assign org.apache.activemq.command.ActiveMQBlobMessage to > org.apache.camel.Message > > > When working with BlobMessages sent normally (via a producer.send()) I am > able to retrieve the BlobMessage this way: > > if (! (((JmsMessage) message).getJmsMessage() instanceof BlobMessage)) > { > throw new CdsMsgException("Error processing batch message: Expected a > BlobMessage"); > } > BlobMessage blobMessage = (BlobMessage) ((JmsMessage) > message).getJmsMessage(); > > But I'm at a loss as to how to change the Message to a BlobMessage inside > of > a DataFormat. > > I assume I'm missing something fairly trivial. > > Thanks, > > > > > ----- > > Brent > -- > View this message in context: > http://camel.465427.n5.nabble.com/Is-it-possible-to-create-a-custom-DataFormat-to-translate-a-message-into-a-BlobMessage-tp5716679p5716720.html > Sent from the Camel - Users mailing list archive at Nabble.com. > |
|
Don't be sorry. I'm still learning and I appreciate the advice. I will explore the message converter.
Thanks, Brent |
|
In reply to this post by pontus.ullgren
I don't think a Converter is the right choice, if you need a JMS connection
for this. How should the Connector know which broker url should be used? You cannot inject dependencies into your converter... Best, Christian On Fri, Aug 3, 2012 at 8:21 AM, Pontus Ullgren <[hidden email]> wrote: > Hello, > > Sorry for repeating myself but you should really have a look at doing this > in a message converter. First you will not have to cast it to a exchange. > And second you will then be handed the same session that is used to create > the producer in the component. So you will participate in the same unit of > work. Which I doubt is true if you create your own connection/session. But > I am currently travelling so I can not test this. > > //Pontus > Send from my phone > Den 3 aug 2012 00:14 skrev "brenthale" <[hidden email]>: > > > Thanks for all the suggestions. > > > > I've been trying to create a DataFormat to handle this. I'm stuck trying > > to > > integrate an ActiveMQ ActiveMQBlobMessage with the > > org.apache.camel.Exchange > > class working with org.apache.camel.Message's. You can't typecast one > into > > the other. > > > > Here's my current unmarshal method: > > > > public Object unmarshal(Exchange exchange, InputStream stream) throws > > Exception { > > ActiveMQConnection connection; > > ActiveMQSession session; > > > > ActiveMQBlobMessage blobMessage; > > > > connection = (ActiveMQConnection) > > activeMQConnectionFactory.createConnection(); > > connection.start(); > > > > session = (ActiveMQSession) connection.createSession(false, > > Session.AUTO_ACKNOWLEDGE); > > > > blobMessage = (ActiveMQBlobMessage) > session.createBlobMessage(stream); > > blobMessage.setMessageId(new > > MessageId(exchange.getIn().getMessageId())); > > > > // Get the data uploaded to the ActiveMQ fileserver > > blobMessage.getBlobUploader().upload(blobMessage); > > > > // org.apache.camel.Exchange is a Camel object expecting a > > org.apache.camel.Message in the Out. > > // BlobMessage is an ActiveMQ > > org.apache.activemq.command.ActiveMQBlobMessage. > > // This line doesn't work. They don't cast. > > // exchange.setOut(blobMessage); > > > > // And this was a sad attempt at trying to get around it. > > // DefaultMessage camelMessage = new DefaultMessage(); > > // camelMessage.setExchange(exchange); > > // camelMessage.setBody(blobMessage, > > org.apache.activemq.command.Message.class); > > // camelMessage.setMessageId(blobMessage.getMessageId().toString()); > > // exchange.setOut(camelMessage); // kinda by-passes things. > > > > // if (! (((JmsMessage) message).getJmsMessage() instanceof > > BlobMessage)) > > { > > exchange.setOut((JmsMessage)(BlobMessage)blobMessage); > > // ((JmsMessage)exchange.getOut()).setJmsMessage(blobMessage); > > > > return blobMessage; > > } > > > > > > When the setOut() is made I get the following exception. > > > > exchange.setOut((JmsMessage)(BlobMessage)blobMessage) = Type mismatch > Can't > > assign org.apache.activemq.command.ActiveMQBlobMessage to > > org.apache.camel.Message > > > > > > When working with BlobMessages sent normally (via a producer.send()) I am > > able to retrieve the BlobMessage this way: > > > > if (! (((JmsMessage) message).getJmsMessage() instanceof > BlobMessage)) > > { > > throw new CdsMsgException("Error processing batch message: > Expected a > > BlobMessage"); > > } > > BlobMessage blobMessage = (BlobMessage) ((JmsMessage) > > message).getJmsMessage(); > > > > But I'm at a loss as to how to change the Message to a BlobMessage inside > > of > > a DataFormat. > > > > I assume I'm missing something fairly trivial. > > > > Thanks, > > > > > > > > > > ----- > > > > Brent > > -- > > View this message in context: > > > http://camel.465427.n5.nabble.com/Is-it-possible-to-create-a-custom-DataFormat-to-translate-a-message-into-a-BlobMessage-tp5716679p5716720.html > > Sent from the Camel - Users mailing list archive at Nabble.com. > > > |
|
I am talking about the (spring) jms message converter used by the jms
component to create jms messages is handed the correct session. See the messageConverter option on the JMS component page. Best regards Pontus Send from my phone Den 4 aug 2012 00:35 skrev "Christian Müller" <[hidden email]>: > I don't think a Converter is the right choice, if you need a JMS connection > for this. How should the Connector know which broker url should be used? > You cannot inject dependencies into your converter... > > Best, > Christian > > On Fri, Aug 3, 2012 at 8:21 AM, Pontus Ullgren <[hidden email]> wrote: > > > Hello, > > > > Sorry for repeating myself but you should really have a look at doing > this > > in a message converter. First you will not have to cast it to a exchange. > > And second you will then be handed the same session that is used to > create > > the producer in the component. So you will participate in the same unit > of > > work. Which I doubt is true if you create your own connection/session. > But > > I am currently travelling so I can not test this. > > > > //Pontus > > Send from my phone > > Den 3 aug 2012 00:14 skrev "brenthale" <[hidden email]>: > > > > > Thanks for all the suggestions. > > > > > > I've been trying to create a DataFormat to handle this. I'm stuck > trying > > > to > > > integrate an ActiveMQ ActiveMQBlobMessage with the > > > org.apache.camel.Exchange > > > class working with org.apache.camel.Message's. You can't typecast one > > into > > > the other. > > > > > > Here's my current unmarshal method: > > > > > > public Object unmarshal(Exchange exchange, InputStream stream) throws > > > Exception { > > > ActiveMQConnection connection; > > > ActiveMQSession session; > > > > > > ActiveMQBlobMessage blobMessage; > > > > > > connection = (ActiveMQConnection) > > > activeMQConnectionFactory.createConnection(); > > > connection.start(); > > > > > > session = (ActiveMQSession) connection.createSession(false, > > > Session.AUTO_ACKNOWLEDGE); > > > > > > blobMessage = (ActiveMQBlobMessage) > > session.createBlobMessage(stream); > > > blobMessage.setMessageId(new > > > MessageId(exchange.getIn().getMessageId())); > > > > > > // Get the data uploaded to the ActiveMQ fileserver > > > blobMessage.getBlobUploader().upload(blobMessage); > > > > > > // org.apache.camel.Exchange is a Camel object expecting a > > > org.apache.camel.Message in the Out. > > > // BlobMessage is an ActiveMQ > > > org.apache.activemq.command.ActiveMQBlobMessage. > > > // This line doesn't work. They don't cast. > > > // exchange.setOut(blobMessage); > > > > > > // And this was a sad attempt at trying to get around it. > > > // DefaultMessage camelMessage = new DefaultMessage(); > > > // camelMessage.setExchange(exchange); > > > // camelMessage.setBody(blobMessage, > > > org.apache.activemq.command.Message.class); > > > // camelMessage.setMessageId(blobMessage.getMessageId().toString()); > > > // exchange.setOut(camelMessage); // kinda by-passes things. > > > > > > // if (! (((JmsMessage) message).getJmsMessage() instanceof > > > BlobMessage)) > > > { > > > exchange.setOut((JmsMessage)(BlobMessage)blobMessage); > > > // ((JmsMessage)exchange.getOut()).setJmsMessage(blobMessage); > > > > > > return blobMessage; > > > } > > > > > > > > > When the setOut() is made I get the following exception. > > > > > > exchange.setOut((JmsMessage)(BlobMessage)blobMessage) = Type mismatch > > Can't > > > assign org.apache.activemq.command.ActiveMQBlobMessage to > > > org.apache.camel.Message > > > > > > > > > When working with BlobMessages sent normally (via a producer.send()) I > am > > > able to retrieve the BlobMessage this way: > > > > > > if (! (((JmsMessage) message).getJmsMessage() instanceof > > BlobMessage)) > > > { > > > throw new CdsMsgException("Error processing batch message: > > Expected a > > > BlobMessage"); > > > } > > > BlobMessage blobMessage = (BlobMessage) ((JmsMessage) > > > message).getJmsMessage(); > > > > > > But I'm at a loss as to how to change the Message to a BlobMessage > inside > > > of > > > a DataFormat. > > > > > > I assume I'm missing something fairly trivial. > > > > > > Thanks, > > > > > > > > > > > > > > > ----- > > > > > > Brent > > > -- > > > View this message in context: > > > > > > http://camel.465427.n5.nabble.com/Is-it-possible-to-create-a-custom-DataFormat-to-translate-a-message-into-a-BlobMessage-tp5716679p5716720.html > > > Sent from the Camel - Users mailing list archive at Nabble.com. > > > > > > |
|
Yeah, I think this is a good idea.
I thought by talking about the "message converter" you mean the Camel type converter mechanism... Best, Christian On Sat, Aug 4, 2012 at 7:09 AM, Pontus Ullgren <[hidden email]> wrote: > I am talking about the (spring) jms message converter used by the jms > component to create jms messages is handed the correct session. > See the messageConverter option on the JMS component page. > > Best regards > Pontus > Send from my phone > Den 4 aug 2012 00:35 skrev "Christian Müller" <[hidden email] > >: > > > I don't think a Converter is the right choice, if you need a JMS > connection > > for this. How should the Connector know which broker url should be used? > > You cannot inject dependencies into your converter... > > > > Best, > > Christian > > > > On Fri, Aug 3, 2012 at 8:21 AM, Pontus Ullgren <[hidden email]> > wrote: > > > > > Hello, > > > > > > Sorry for repeating myself but you should really have a look at doing > > this > > > in a message converter. First you will not have to cast it to a > exchange. > > > And second you will then be handed the same session that is used to > > create > > > the producer in the component. So you will participate in the same unit > > of > > > work. Which I doubt is true if you create your own connection/session. > > But > > > I am currently travelling so I can not test this. > > > > > > //Pontus > > > Send from my phone > > > Den 3 aug 2012 00:14 skrev "brenthale" <[hidden email]>: > > > > > > > Thanks for all the suggestions. > > > > > > > > I've been trying to create a DataFormat to handle this. I'm stuck > > trying > > > > to > > > > integrate an ActiveMQ ActiveMQBlobMessage with the > > > > org.apache.camel.Exchange > > > > class working with org.apache.camel.Message's. You can't typecast > one > > > into > > > > the other. > > > > > > > > Here's my current unmarshal method: > > > > > > > > public Object unmarshal(Exchange exchange, InputStream stream) > throws > > > > Exception { > > > > ActiveMQConnection connection; > > > > ActiveMQSession session; > > > > > > > > ActiveMQBlobMessage blobMessage; > > > > > > > > connection = (ActiveMQConnection) > > > > activeMQConnectionFactory.createConnection(); > > > > connection.start(); > > > > > > > > session = (ActiveMQSession) connection.createSession(false, > > > > Session.AUTO_ACKNOWLEDGE); > > > > > > > > blobMessage = (ActiveMQBlobMessage) > > > session.createBlobMessage(stream); > > > > blobMessage.setMessageId(new > > > > MessageId(exchange.getIn().getMessageId())); > > > > > > > > // Get the data uploaded to the ActiveMQ fileserver > > > > blobMessage.getBlobUploader().upload(blobMessage); > > > > > > > > // org.apache.camel.Exchange is a Camel object expecting a > > > > org.apache.camel.Message in the Out. > > > > // BlobMessage is an ActiveMQ > > > > org.apache.activemq.command.ActiveMQBlobMessage. > > > > // This line doesn't work. They don't cast. > > > > // exchange.setOut(blobMessage); > > > > > > > > // And this was a sad attempt at trying to get around it. > > > > // DefaultMessage camelMessage = new DefaultMessage(); > > > > // camelMessage.setExchange(exchange); > > > > // camelMessage.setBody(blobMessage, > > > > org.apache.activemq.command.Message.class); > > > > // > camelMessage.setMessageId(blobMessage.getMessageId().toString()); > > > > // exchange.setOut(camelMessage); // kinda by-passes things. > > > > > > > > // if (! (((JmsMessage) message).getJmsMessage() instanceof > > > > BlobMessage)) > > > > { > > > > exchange.setOut((JmsMessage)(BlobMessage)blobMessage); > > > > // ((JmsMessage)exchange.getOut()).setJmsMessage(blobMessage); > > > > > > > > return blobMessage; > > > > } > > > > > > > > > > > > When the setOut() is made I get the following exception. > > > > > > > > exchange.setOut((JmsMessage)(BlobMessage)blobMessage) = Type mismatch > > > Can't > > > > assign org.apache.activemq.command.ActiveMQBlobMessage to > > > > org.apache.camel.Message > > > > > > > > > > > > When working with BlobMessages sent normally (via a producer.send()) > I > > am > > > > able to retrieve the BlobMessage this way: > > > > > > > > if (! (((JmsMessage) message).getJmsMessage() instanceof > > > BlobMessage)) > > > > { > > > > throw new CdsMsgException("Error processing batch message: > > > Expected a > > > > BlobMessage"); > > > > } > > > > BlobMessage blobMessage = (BlobMessage) ((JmsMessage) > > > > message).getJmsMessage(); > > > > > > > > But I'm at a loss as to how to change the Message to a BlobMessage > > inside > > > > of > > > > a DataFormat. > > > > > > > > I assume I'm missing something fairly trivial. > > > > > > > > Thanks, > > > > > > > > > > > > > > > > > > > > ----- > > > > > > > > Brent > > > > -- > > > > View this message in context: > > > > > > > > > > http://camel.465427.n5.nabble.com/Is-it-possible-to-create-a-custom-DataFormat-to-translate-a-message-into-a-BlobMessage-tp5716679p5716720.html > > > > Sent from the Camel - Users mailing list archive at Nabble.com. > > > > > > > > > > |
|
In reply to this post by pontus.ullgren
On Sat, Aug 4, 2012 at 7:09 AM, Pontus Ullgren <[hidden email]> wrote:
> I am talking about the (spring) jms message converter used by the jms > component to create jms messages is handed the correct session. > See the messageConverter option on the JMS component page. > Yes you should use a JMS message converter on the JMS component. This is likely the only possible solution as its then tied to the JMS API and the JMS session as Pontus says. Using a DataFormat is not really possible. > Best regards > Pontus > Send from my phone > Den 4 aug 2012 00:35 skrev "Christian Müller" <[hidden email]>: > >> I don't think a Converter is the right choice, if you need a JMS connection >> for this. How should the Connector know which broker url should be used? >> You cannot inject dependencies into your converter... >> >> Best, >> Christian >> >> On Fri, Aug 3, 2012 at 8:21 AM, Pontus Ullgren <[hidden email]> wrote: >> >> > Hello, >> > >> > Sorry for repeating myself but you should really have a look at doing >> this >> > in a message converter. First you will not have to cast it to a exchange. >> > And second you will then be handed the same session that is used to >> create >> > the producer in the component. So you will participate in the same unit >> of >> > work. Which I doubt is true if you create your own connection/session. >> But >> > I am currently travelling so I can not test this. >> > >> > //Pontus >> > Send from my phone >> > Den 3 aug 2012 00:14 skrev "brenthale" <[hidden email]>: >> > >> > > Thanks for all the suggestions. >> > > >> > > I've been trying to create a DataFormat to handle this. I'm stuck >> trying >> > > to >> > > integrate an ActiveMQ ActiveMQBlobMessage with the >> > > org.apache.camel.Exchange >> > > class working with org.apache.camel.Message's. You can't typecast one >> > into >> > > the other. >> > > >> > > Here's my current unmarshal method: >> > > >> > > public Object unmarshal(Exchange exchange, InputStream stream) throws >> > > Exception { >> > > ActiveMQConnection connection; >> > > ActiveMQSession session; >> > > >> > > ActiveMQBlobMessage blobMessage; >> > > >> > > connection = (ActiveMQConnection) >> > > activeMQConnectionFactory.createConnection(); >> > > connection.start(); >> > > >> > > session = (ActiveMQSession) connection.createSession(false, >> > > Session.AUTO_ACKNOWLEDGE); >> > > >> > > blobMessage = (ActiveMQBlobMessage) >> > session.createBlobMessage(stream); >> > > blobMessage.setMessageId(new >> > > MessageId(exchange.getIn().getMessageId())); >> > > >> > > // Get the data uploaded to the ActiveMQ fileserver >> > > blobMessage.getBlobUploader().upload(blobMessage); >> > > >> > > // org.apache.camel.Exchange is a Camel object expecting a >> > > org.apache.camel.Message in the Out. >> > > // BlobMessage is an ActiveMQ >> > > org.apache.activemq.command.ActiveMQBlobMessage. >> > > // This line doesn't work. They don't cast. >> > > // exchange.setOut(blobMessage); >> > > >> > > // And this was a sad attempt at trying to get around it. >> > > // DefaultMessage camelMessage = new DefaultMessage(); >> > > // camelMessage.setExchange(exchange); >> > > // camelMessage.setBody(blobMessage, >> > > org.apache.activemq.command.Message.class); >> > > // camelMessage.setMessageId(blobMessage.getMessageId().toString()); >> > > // exchange.setOut(camelMessage); // kinda by-passes things. >> > > >> > > // if (! (((JmsMessage) message).getJmsMessage() instanceof >> > > BlobMessage)) >> > > { >> > > exchange.setOut((JmsMessage)(BlobMessage)blobMessage); >> > > // ((JmsMessage)exchange.getOut()).setJmsMessage(blobMessage); >> > > >> > > return blobMessage; >> > > } >> > > >> > > >> > > When the setOut() is made I get the following exception. >> > > >> > > exchange.setOut((JmsMessage)(BlobMessage)blobMessage) = Type mismatch >> > Can't >> > > assign org.apache.activemq.command.ActiveMQBlobMessage to >> > > org.apache.camel.Message >> > > >> > > >> > > When working with BlobMessages sent normally (via a producer.send()) I >> am >> > > able to retrieve the BlobMessage this way: >> > > >> > > if (! (((JmsMessage) message).getJmsMessage() instanceof >> > BlobMessage)) >> > > { >> > > throw new CdsMsgException("Error processing batch message: >> > Expected a >> > > BlobMessage"); >> > > } >> > > BlobMessage blobMessage = (BlobMessage) ((JmsMessage) >> > > message).getJmsMessage(); >> > > >> > > But I'm at a loss as to how to change the Message to a BlobMessage >> inside >> > > of >> > > a DataFormat. >> > > >> > > I assume I'm missing something fairly trivial. >> > > >> > > Thanks, >> > > >> > > >> > > >> > > >> > > ----- >> > > >> > > Brent >> > > -- >> > > View this message in context: >> > > >> > >> http://camel.465427.n5.nabble.com/Is-it-possible-to-create-a-custom-DataFormat-to-translate-a-message-into-a-BlobMessage-tp5716679p5716720.html >> > > Sent from the Camel - Users mailing list archive at Nabble.com. >> > > >> > >> -- Claus Ibsen ----------------- FuseSource Email: [hidden email] Web: http://fusesource.com Twitter: davsclaus, fusenews Blog: http://davsclaus.com Author of Camel in Action: http://www.manning.com/ibsen |
| Powered by Nabble | Edit this page |
