You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by Mick Knutson <mk...@baselogic.com> on 2008/09/24 00:34:32 UTC
Re: Trying to understand how to deal with process() errors and creating an exceptionChannel for bad messages.
Can anyone help me on this?
On Tue, Sep 23, 2008 at 2:00 PM, Mick Knutson <mk...@baselogic.com>wrote:
> To give some background here is my process:
>
> *public void process(Exchange exchange)
> throws Exception {
> log.info("process ChangeRequestInputTransformer request");
>
> String body = (String) exchange.getIn().getBody();
>
> // Get a Map of Items from the input message
> JSONObject jsonIn = new JSONObject(body);
>
> // validate input message, route to verifyErrorEndpoint if there
> are errors.
> String customerId = jsonIn.getString(Constants.CUSTOMER_ID);
> String type = jsonIn.getString(Constants.CHANGEREQUST_TYPE);
> String quota = jsonIn.getString(Constants.QUOTA);
>
> ChangeRequest changeRequest = null;
>
> try {
>
> if (type.equalsIgnoreCase(Constants.PROVISION)) {
> log.info("***** PROVISION *****");
> changeRequest = createProvisionChangeRequest(customerId,
> quota); // can throw Exception
> exchange.getOut().setHeader(Constants.REQUEST_DESTINATION,
> Constants.REQUEST_OUTPUT_CHANNEL);
>
> } else if (type.equalsIgnoreCase(Constants.DEPROVISION)) {
> log.info("DEPROVISION");
> } else {
> log.error("Invalid Change Request");
> exchange.getOut().setHeader(Constants.REQUEST_DESTINATION,
> Constants.REQUEST_INPUT_ERROR_CHANNEL);
> }
>
> String jsonOut = toJSON(body);
>
> exchange.getOut().setMessageId(changeRequest.getChangeRequestId()
> + "");
> exchange.getOut().setHeader(Constants.CORRELATION_ID,
> changeRequest.getChangeRequestId());
> exchange.getOut().setHeader(Constants.TIMEOUT, new
> Integer(5000)); // fixme: 5 seconds....
> exchange.getOut().setHeader(Constants.CUSTOMER_ID,
> changeRequest.getCustomerId());
>
> exchange.getOut().setBody(jsonOut);
>
> //todo need to rout to CR_INPUT_ERROR_CHANNEL if there is an
> error.
>
> log.info("*********************************");
> } catch (Exception e) {
> exchange.isFailed();
> throw new Exception("Error creating Change Request");
> }
> }
> *
>
> Now, I get an exception with *exchange.getOut().setMessageId(changeRequest.getChangeRequestId()
> + ""); *but my mock still gets the expected number of messages.
>
> so I need to understand how to stop the current message, and redirect this
> to an error channel instead.
>
>
>
>
> On Tue, Sep 23, 2008 at 1:50 PM, Mick Knutson <mk...@baselogic.com>wrote:
>
>> I have input messages that I am trying to process, and when there is an
>> error, I want to create a new exceptionMessage and put it onto an
>> inputErrorChannel .
>>
>>
>>
>> --
>> ---
>> Thank You…
>>
>> Mick Knutson
>> BASE Logic, inc.
>> (415) 354-4215
>>
>> Website: http://baselogic.com
>> Blog: http://baselogic.com/blog
>> BLiNC Magazine: http://blincmagazine.com
>> Linked IN: http://linkedin.com/in/mickknutson
>> DJ Mick: http://djmick.com
>> MySpace: http://myspace.com/mickknutson
>> Vacation Rental: http://tahoe.baselogic.com
>>
>>
>
>
> --
> ---
> Thank You…
>
> Mick Knutson
> BASE Logic, inc.
> (415) 354-4215
>
> Website: http://baselogic.com
> Blog: http://baselogic.com/blog
> BLiNC Magazine: http://blincmagazine.com
> Linked IN: http://linkedin.com/in/mickknutson
> DJ Mick: http://djmick.com
> MySpace: http://myspace.com/mickknutson
> Vacation Rental: http://tahoe.baselogic.com
>
>
--
---
Thank You…
Mick Knutson
BASE Logic, inc.
(415) 354-4215
Website: http://baselogic.com
Blog: http://baselogic.com/blog
BLiNC Magazine: http://blincmagazine.com
Linked IN: http://linkedin.com/in/mickknutson
DJ Mick: http://djmick.com
MySpace: http://myspace.com/mickknutson
Vacation Rental: http://tahoe.baselogic.com