concept interceptor in category camel

appears as: n interceptor, interceptors, interceptors, interceptor, interceptor
Camel in Action

This is an excerpt from Manning's book Camel in Action.

In Camel, routing is a more general concept. It’s defined as a step-by-step movement of the message, which originates from an endpoint in the role of a consumer. The consumer could be receiving the message from an external service, polling for the message on a system, or even creating the message itself. This message then flows through a processing node, which could be an enterprise integration pattern (EIP), a processor, an interceptor, or another custom creation. The message is finally sent to a target endpoint that’s in the role of a producer. A route may have many processing components that modify the message or send it to another location, or it may have none, in which case it would be a simple pipeline.

9.4.3 Simulating errors using interceptors

Suppose your boss wants you to write integration tests for the example from section 9.4.1 that should, among other things, test what happens when communication with the remote HTTP server fails. How can you do that? It’s tricky because you don’t have control over the remote HTTP server, and you can’t easily force communication errors in the network layer. Luckily, Camel provides features to address this problem. We’ll get to that in a moment, but first you need to look at interceptors, which provide the means to simulate errors.

In a nutshell, an interceptor allows you to intercept any given message and act on it. Figure 9.5 illustrates where the interception takes place in a route.

Figure 9.5 The channel acts as a controller, and it's where messages are intercepted during routing.

c09_05.png

Figure 9.5 shows a low-level view of a Camel route, whereby you route messages from a file consumer to an HTTP producer. In between sits the channel, which acts as a controller, and this is where the interceptors (among others) live.

@Test public void testSimulateErrorUsingInterceptors() throws Exception { RouteDefinition route = context.getRouteDefinitions().get(0);     #1 route.adviceWith(context, new RouteBuilder() {     #2 public void configure() throws Exception { interceptSendToEndpoint("http://*") .skipSendToOriginalEndpoint() .process(new SimulateHttpErrorProcessor()); } }); .. } #1 Selects the first route to be advised #2 Uses adviceWith to add interceptor to route

Interceptors aren’t only for simulating errors; they’re a general-purpose feature that can also be used for other types of testing. For example, when you’re testing production routes, you can use interceptors to detour messages to mock endpoints.

Camel in Action

This is an excerpt from Manning's book Camel in Action.

In Apache Camel, routing is a more general concept. It’s defined as a step-by-step movement of the message, which originates from an endpoint in the role of a consumer. The consumer could be receiving the message from an external service, polling for the message on some system, or even creating the message itself. This message then flows through a processing component, which could be an enterprise integration pattern (EIP), a processor, an interceptor, or some other custom creation. The message is finally sent to a target endpoint that’s in the role of a producer. A route may have many processing components that modify the message or send it to another location, or it may have none, in which case it would be a simple pipeline.

6.3.3. Simulating errors using interceptors

Suppose your boss wants you to write integration tests for listing 6.10 that should, among other things, test what happens when communication with the remote HTTP server fails. How can you do that? This is tricky because you don’t have control over the remote HTTP server, and you can’t easily force communication errors in the network layer. Luckily, Camel provides features to address this problem. We’ll get to that in a moment, but first we need to look at interceptors, which provide the means to simulate errors.

In a nutshell, an interceptor allows you to intercept any given message and act upon it. Figure 6.4 illustrates where the interception takes place in a route.

Figure 6.4. The channel acts as a controller, and it’s where messages are intercepted during routing.

Figure 6.4 shows a low-level view of a Camel route, where you route messages from a file consumer to an HTTP producer. In between sits the channel, which acts as a controller, and this is where the interceptors (among others) live.

Interceptors aren’t only for simulating errors—they’re a general purpose feature that can also be used for other types of testing. For example, when you’re testing production routes, you can use interceptors to detour messages to mock endpoints.