io.fabric8.mq.interceptors.camel.MQConsumer Maven / Gradle / Ivy
/*
*
* * Copyright 2005-2015 Red Hat, Inc.
* * Red Hat licenses this file to you under the Apache License, version
* * 2.0 (the "License"); you may not use this file except in compliance
* * with the License. You may obtain a copy of the License at
* * http://www.apache.org/licenses/LICENSE-2.0
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* * implied. See the License for the specific language governing
* * permissions and limitations under the License.
*
*/
package io.fabric8.mq.interceptors.camel;
import io.fabric8.mq.interceptors.MessageInterceptor;
import io.fabric8.mq.interceptors.MessageRouter;
import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
import org.apache.camel.ExchangePattern;
import org.apache.camel.Processor;
import org.apache.camel.component.jms.JmsBinding;
import org.apache.camel.impl.DefaultConsumer;
public class MQConsumer extends DefaultConsumer implements MessageInterceptor {
private final JmsBinding jmsBinding = new JmsBinding();
public MQConsumer(Endpoint endpoint, Processor processor) {
super(endpoint, processor);
}
@Override
protected void doStart() throws Exception {
super.doStart();
((MQEndpoint) getEndpoint()).addMessageInterceptor(this);
}
@Override
protected void doStop() throws Exception {
((MQEndpoint) getEndpoint()).removeMessageInterceptor(this);
super.doStop();
}
@Override
public void intercept(MessageRouter messageRouter, CommandMessage message) {
Exchange exchange = getEndpoint().createExchange(ExchangePattern.InOnly);
exchange.setIn(message);
try {
getProcessor().process(exchange);
} catch (Exception e) {
exchange.setException(e);
}
if (exchange.getException() != null) {
getExceptionHandler().handleException("Error processing intercepted message: " + message, exchange, exchange.getException());
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy