You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by fjelmer <fr...@systemsx.ch> on 2008/10/15 13:33:36 UTC

Exchange FAULT message does not work

I want to use Exchange.getFault() message to return to a message producer
that something went wrong at the receiver when processing the received
message. This works fine for component type 'direct'. It didn't work with
JMS. Here is an example:

public class FaultExample
{

    public static void main(String[] args) throws Exception
    {
        CamelContext context = new DefaultCamelContext();
        context.addComponent("jms",
                JmsComponent.jmsComponentClientAcknowledge(new
ActiveMQConnectionFactory(
                        "vm://localhost:61616")));
        final String uri = "jms:a";
        context.addRoutes(new RouteBuilder()
            {
                @Override
                public void configure() throws Exception
                {
                    from(uri).process(new Processor()
                        {
                            public void process(Exchange exchange) throws
Exception
                            {
                                System.out.println("Processing " +
exchange.getIn());
                                exchange.getFault().setBody("fault!");
                            }
                        });
                }
            });
        context.start();
        Endpoint<Exchange> endpoint = context.getEndpoint(uri);
        Exchange exchange = endpoint.createExchange(ExchangePattern.InOut);
        exchange.getIn().setBody("hello world");
        Exchange result =
context.<Exchange>createProducerTemplate().send(endpoint, exchange);
        System.out.println("result.out: " + result.getOut());
        System.out.println("result.fault: " + result.getFault());
        System.out.println("result.failed: " + result.isFailed());
        System.out.println("result.exception: " + result.getException());
        context.stop();
        System.out.println("context stopped");
    }
}

If uri = "direct:a" I get

Processing Message: hello world
result.out: Message: null
result.fault: Message: fault!
result.failed: true
result.exception: null
context stopped

If uri = "jms:a" I get

Processing JmsMessage: ActiveMQTextMessage {commandId = 5, responseRequired
= true, messageId = ID:cisd-tp01-2749-1224069364072-2:2:1:1:1,
originalDestination = null, originalTransactionId = null, producerId =
ID:cisd-tp01-2749-1224069364072-2:2:1:1, destination = queue://a,
transactionId = null, expiration = 1224069388445, timestamp = 1224069368445,
arrival = 0, brokerInTime = 1224069368445, brokerOutTime = 1224069368461,
correlationId = ID-cisd-tp01/2750-1224069364587/2-0, replyTo =
temp-queue://ID:cisd-tp01-2749-1224069364072-2:1:1, persistent = true, type
= null, priority = 4, groupID = null, groupSequence = 0, targetConsumerId =
null, compressed = false, userID = null, content =
org.apache.activemq.util.ByteSequence@10d3f0d, marshalledProperties = null,
dataStructure = null, redeliveryCounter = 0, size = 1039, properties = null,
readOnlyProperties = true, readOnlyBody = true, droppable = false, text =
null}
result.out: JmsMessage: null
result.fault: JmsMessage: null
result.failed: true
result.exception: org.apache.camel.ExchangeTimedOutException: The OUT
message was not received within: 20000 millis on the exchange:
Exchange[JmsMessage: hello world]
context stopped

BTW the application does not stop (i.e. the VM is still running). 

If I add the following line to method process() of the Processor

                                exchange.getOut().setBody("");

there is no longer a timeout exception but there is still no expected FAULT
message even though it has been set.

Is this a bug or did I something wrong?

Regards
Franz-Josef Elmer



-- 
View this message in context: http://www.nabble.com/Exchange-FAULT-message-does-not-work-tp19991688s22882p19991688.html
Sent from the Camel - Users mailing list archive at Nabble.com.


RE: Exchange FAULT message does not work

Posted by Claus Ibsen <ci...@silverbullet.dk>.
Hi

If you use the other components such as: seda, direct etc. then the FAULT stuff works, as they are used in the same JVM.

JMS is used for communication between external systems, so the payload being sent is low-level such as Text or bytes.

However we have a few tickets to be able to enhance this but with some options so end-users can turn this on/off, but knowing the consequences.
http://issues.apache.org/activemq/browse/CAMEL-870
http://issues.apache.org/activemq/browse/CAMEL-585
http://issues.apache.org/activemq/browse/CAMEL-898


Feel free to create a ticket for your issue with the FAULT.
 



Med venlig hilsen
 
Claus Ibsen
......................................
Silverbullet
Skovsgårdsvænget 21
8362 Hørning
Tlf. +45 2962 7576
Web: www.silverbullet.dk

-----Original Message-----
From: fjelmer [mailto:franz-josef.elmer@systemsx.ch] 
Sent: 16. oktober 2008 08:36
To: camel-user@activemq.apache.org
Subject: RE: Exchange FAULT message does not work


Hi Claus

Thanks for the quick response.

I've tried the 1.5 SNAPSHOT (apache.camel-1.5-20081014.230339-121.zip) and
it doesn't work as expected: Now the FAULT message is returned as an OUT
message and the isFailed flag is still false.

Regards
Franz-Josef

-- 
View this message in context: http://www.nabble.com/Exchange-FAULT-message-does-not-work-tp19991688s22882p20007977.html
Sent from the Camel - Users mailing list archive at Nabble.com.


RE: Exchange FAULT message does not work

Posted by Claus Ibsen <ci...@silverbullet.dk>.
Hi

The JMS component can only be used for transferring a payload and the simple headers according to the JMS spec. So I am afraid you have to do some manual processing of the returned response to handle what you consider a FAULT.

We might be able to slip in some custom header in the JMS properties indicating that it's a FAULT message. But yet again, the FAULT/Exception stuff is up for a redesign in Camel 2.0. 




Med venlig hilsen
 
Claus Ibsen
......................................
Silverbullet
Skovsgårdsvænget 21
8362 Hørning
Tlf. +45 2962 7576
Web: www.silverbullet.dk
-----Original Message-----
From: fjelmer [mailto:franz-josef.elmer@systemsx.ch] 
Sent: 16. oktober 2008 08:36
To: camel-user@activemq.apache.org
Subject: RE: Exchange FAULT message does not work


Hi Claus

Thanks for the quick response.

I've tried the 1.5 SNAPSHOT (apache.camel-1.5-20081014.230339-121.zip) and
it doesn't work as expected: Now the FAULT message is returned as an OUT
message and the isFailed flag is still false.

Regards
Franz-Josef

-- 
View this message in context: http://www.nabble.com/Exchange-FAULT-message-does-not-work-tp19991688s22882p20007977.html
Sent from the Camel - Users mailing list archive at Nabble.com.


RE: Exchange FAULT message does not work

Posted by fjelmer <fr...@systemsx.ch>.
Hi Claus

Thanks for the quick response.

I've tried the 1.5 SNAPSHOT (apache.camel-1.5-20081014.230339-121.zip) and
it doesn't work as expected: Now the FAULT message is returned as an OUT
message and the isFailed flag is still false.

Regards
Franz-Josef

-- 
View this message in context: http://www.nabble.com/Exchange-FAULT-message-does-not-work-tp19991688s22882p20007977.html
Sent from the Camel - Users mailing list archive at Nabble.com.


RE: Exchange FAULT message does not work

Posted by Claus Ibsen <ci...@silverbullet.dk>.
Hi

I think this has been fixed in the 1.5-SNAPSHOT

You can get the 1.5-SNAPSHOT from the download page:
http://activemq.apache.org/camel/download.html



Med venlig hilsen
 
Claus Ibsen
......................................
Silverbullet
Skovsgårdsvænget 21
8362 Hørning
Tlf. +45 2962 7576
Web: www.silverbullet.dk

-----Original Message-----
From: fjelmer [mailto:franz-josef.elmer@systemsx.ch] 
Sent: 15. oktober 2008 13:34
To: camel-user@activemq.apache.org
Subject: Exchange FAULT message does not work


I want to use Exchange.getFault() message to return to a message producer
that something went wrong at the receiver when processing the received
message. This works fine for component type 'direct'. It didn't work with
JMS. Here is an example:

public class FaultExample
{

    public static void main(String[] args) throws Exception
    {
        CamelContext context = new DefaultCamelContext();
        context.addComponent("jms",
                JmsComponent.jmsComponentClientAcknowledge(new
ActiveMQConnectionFactory(
                        "vm://localhost:61616")));
        final String uri = "jms:a";
        context.addRoutes(new RouteBuilder()
            {
                @Override
                public void configure() throws Exception
                {
                    from(uri).process(new Processor()
                        {
                            public void process(Exchange exchange) throws
Exception
                            {
                                System.out.println("Processing " +
exchange.getIn());
                                exchange.getFault().setBody("fault!");
                            }
                        });
                }
            });
        context.start();
        Endpoint<Exchange> endpoint = context.getEndpoint(uri);
        Exchange exchange = endpoint.createExchange(ExchangePattern.InOut);
        exchange.getIn().setBody("hello world");
        Exchange result =
context.<Exchange>createProducerTemplate().send(endpoint, exchange);
        System.out.println("result.out: " + result.getOut());
        System.out.println("result.fault: " + result.getFault());
        System.out.println("result.failed: " + result.isFailed());
        System.out.println("result.exception: " + result.getException());
        context.stop();
        System.out.println("context stopped");
    }
}

If uri = "direct:a" I get

Processing Message: hello world
result.out: Message: null
result.fault: Message: fault!
result.failed: true
result.exception: null
context stopped

If uri = "jms:a" I get

Processing JmsMessage: ActiveMQTextMessage {commandId = 5, responseRequired
= true, messageId = ID:cisd-tp01-2749-1224069364072-2:2:1:1:1,
originalDestination = null, originalTransactionId = null, producerId =
ID:cisd-tp01-2749-1224069364072-2:2:1:1, destination = queue://a,
transactionId = null, expiration = 1224069388445, timestamp = 1224069368445,
arrival = 0, brokerInTime = 1224069368445, brokerOutTime = 1224069368461,
correlationId = ID-cisd-tp01/2750-1224069364587/2-0, replyTo =
temp-queue://ID:cisd-tp01-2749-1224069364072-2:1:1, persistent = true, type
= null, priority = 4, groupID = null, groupSequence = 0, targetConsumerId =
null, compressed = false, userID = null, content =
org.apache.activemq.util.ByteSequence@10d3f0d, marshalledProperties = null,
dataStructure = null, redeliveryCounter = 0, size = 1039, properties = null,
readOnlyProperties = true, readOnlyBody = true, droppable = false, text =
null}
result.out: JmsMessage: null
result.fault: JmsMessage: null
result.failed: true
result.exception: org.apache.camel.ExchangeTimedOutException: The OUT
message was not received within: 20000 millis on the exchange:
Exchange[JmsMessage: hello world]
context stopped

BTW the application does not stop (i.e. the VM is still running). 

If I add the following line to method process() of the Processor

                                exchange.getOut().setBody("");

there is no longer a timeout exception but there is still no expected FAULT
message even though it has been set.

Is this a bug or did I something wrong?

Regards
Franz-Josef Elmer



-- 
View this message in context: http://www.nabble.com/Exchange-FAULT-message-does-not-work-tp19991688s22882p19991688.html
Sent from the Camel - Users mailing list archive at Nabble.com.