Reformating configuration and examples for PDF (Scala, and leftovers). See #2413
This commit is contained in:
parent
309bb53d98
commit
08ef942242
46 changed files with 330 additions and 191 deletions
|
|
@ -28,13 +28,15 @@ public class ActivationTestBase {
|
|||
Camel camel = CamelExtension.get(system);
|
||||
// get a future reference to the activation of the endpoint of the Consumer Actor
|
||||
Timeout timeout = new Timeout(Duration.create(10, SECONDS));
|
||||
Future<ActorRef> activationFuture = camel.activationFutureFor(producer, timeout, system.dispatcher());
|
||||
Future<ActorRef> activationFuture = camel.activationFutureFor(producer,
|
||||
timeout, system.dispatcher());
|
||||
//#CamelActivation
|
||||
//#CamelDeactivation
|
||||
// ..
|
||||
system.stop(producer);
|
||||
// get a future reference to the deactivation of the endpoint of the Consumer Actor
|
||||
Future<ActorRef> deactivationFuture = camel.deactivationFutureFor(producer, timeout, system.dispatcher());
|
||||
Future<ActorRef> deactivationFuture = camel.deactivationFutureFor(producer,
|
||||
timeout, system.dispatcher());
|
||||
//#CamelDeactivation
|
||||
system.shutdown();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,8 @@ public class CamelExtensionTestBase {
|
|||
ActorSystem system = ActorSystem.create("some-system");
|
||||
Camel camel = CamelExtension.get(system);
|
||||
CamelContext camelContext = camel.context();
|
||||
// camelContext.addComponent("activemq", ActiveMQComponent.activeMQComponent("vm://localhost?broker.persistent=false"))
|
||||
// camelContext.addComponent("activemq", ActiveMQComponent.activeMQComponent(
|
||||
// "vm://localhost?broker.persistent=false"));
|
||||
//#CamelExtensionAddComponent
|
||||
system.shutdown();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,8 @@ import scala.concurrent.util.FiniteDuration;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class Consumer4 extends UntypedConsumerActor {
|
||||
private final static FiniteDuration timeout = Duration.create(500, TimeUnit.MILLISECONDS);
|
||||
private final static FiniteDuration timeout =
|
||||
Duration.create(500, TimeUnit.MILLISECONDS);
|
||||
|
||||
@Override
|
||||
public FiniteDuration replyTimeout() {
|
||||
|
|
|
|||
|
|
@ -12,12 +12,15 @@ import scala.Option;
|
|||
public class ErrorThrowingConsumer extends UntypedConsumerActor{
|
||||
private String uri;
|
||||
|
||||
private static Mapper<RouteDefinition, ProcessorDefinition<?>> mapper = new Mapper<RouteDefinition, ProcessorDefinition<?>>() {
|
||||
public ProcessorDefinition<?> apply(RouteDefinition rd) {
|
||||
// Catch any exception and handle it by returning the exception message as response
|
||||
return rd.onException(Exception.class).handled(true).transform(Builder.exceptionMessage()).end();
|
||||
}
|
||||
};
|
||||
private static Mapper<RouteDefinition, ProcessorDefinition<?>> mapper =
|
||||
new Mapper<RouteDefinition, ProcessorDefinition<?>>() {
|
||||
public ProcessorDefinition<?> apply(RouteDefinition rd) {
|
||||
// Catch any exception and handle it by returning the exception message
|
||||
// as response
|
||||
return rd.onException(Exception.class).handled(true).
|
||||
transform(Builder.exceptionMessage()).end();
|
||||
}
|
||||
};
|
||||
|
||||
public ErrorThrowingConsumer(String uri){
|
||||
this.uri = uri;
|
||||
|
|
@ -37,7 +40,8 @@ public class ErrorThrowingConsumer extends UntypedConsumerActor{
|
|||
}
|
||||
|
||||
@Override
|
||||
public Mapper<RouteDefinition, ProcessorDefinition<?>> getRouteDefinitionHandler() {
|
||||
public Mapper<RouteDefinition,
|
||||
ProcessorDefinition<?>> getRouteDefinitionHandler() {
|
||||
return mapper;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,7 +39,8 @@ public class ProducerTestBase {
|
|||
ActorRef producer = system.actorOf(props,"jmsproducer");
|
||||
Map<String,Object> headers = new HashMap<String, Object>();
|
||||
headers.put(CamelMessage.MessageExchangeId(),"123");
|
||||
producer.tell(new CamelMessage("<order amount=\"100\" currency=\"PLN\" itemId=\"12345\"/>",headers), null);
|
||||
producer.tell(new CamelMessage("<order amount=\"100\" currency=\"PLN\" " +
|
||||
"itemId=\"12345\"/>",headers), null);
|
||||
//#Correlate
|
||||
system.stop(producer);
|
||||
system.shutdown();
|
||||
|
|
|
|||
|
|
@ -6,7 +6,8 @@ public class HttpSample {
|
|||
public static void main(String[] args) {
|
||||
//#HttpExample
|
||||
// Create the actors. this can be done in a Boot class so you can
|
||||
// run the example in the MicroKernel. just add the below three lines to your boot class.
|
||||
// run the example in the MicroKernel. just add the three lines to below
|
||||
// your boot class.
|
||||
ActorSystem system = ActorSystem.create("some-system");
|
||||
final ActorRef httpTransformer = system.actorOf(new Props(HttpTransformer.class));
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,8 @@ public class HttpTransformer extends UntypedActor{
|
|||
public void onReceive(Object message) {
|
||||
if (message instanceof CamelMessage) {
|
||||
CamelMessage camelMessage = (CamelMessage) message;
|
||||
CamelMessage replacedMessage = camelMessage.mapBody(new Mapper<Object, String>(){
|
||||
CamelMessage replacedMessage =
|
||||
camelMessage.mapBody(new Mapper<Object, String>(){
|
||||
@Override
|
||||
public String apply(Object body) {
|
||||
String text = new String((byte[])body);
|
||||
|
|
|
|||
|
|
@ -19,7 +19,8 @@ public class Consumer3 extends UntypedConsumerActor{
|
|||
public void onReceive(Object message) {
|
||||
if (message instanceof CamelMessage) {
|
||||
CamelMessage camelMessage = (CamelMessage) message;
|
||||
transformer.forward(camelMessage.getBodyAs(String.class, getCamelContext()),getContext());
|
||||
transformer.forward(camelMessage.getBodyAs(String.class, getCamelContext()),
|
||||
getContext());
|
||||
} else
|
||||
unhandled(message);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,8 @@ public class CustomRouteBuilder extends RouteBuilder{
|
|||
public void configure() throws Exception {
|
||||
from("direct:welcome").process(new Processor(){
|
||||
public void process(Exchange exchange) throws Exception {
|
||||
exchange.getOut().setBody(String.format("Welcome %s",exchange.getIn().getBody()));
|
||||
exchange.getOut().setBody(String.format("Welcome %s",
|
||||
exchange.getIn().getBody()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,8 @@ public class CustomRouteSample {
|
|||
public static void main(String[] args) {
|
||||
try {
|
||||
//#CustomRouteExample
|
||||
// the below lines can be added to a Boot class, so that you can run the example from a MicroKernel
|
||||
// the below lines can be added to a Boot class, so that you can run the
|
||||
// example from a MicroKernel
|
||||
ActorSystem system = ActorSystem.create("some-system");
|
||||
final ActorRef producer = system.actorOf(new Props(Producer1.class));
|
||||
final ActorRef mediator = system.actorOf(new Props(new UntypedActorFactory() {
|
||||
|
|
|
|||
|
|
@ -15,14 +15,16 @@ public class Transformer extends UntypedActor {
|
|||
|
||||
public void onReceive(Object message) {
|
||||
if (message instanceof CamelMessage) {
|
||||
// example: transform message body "foo" to "- foo -" and forward result to producer
|
||||
// example: transform message body "foo" to "- foo -" and forward result
|
||||
// to producer
|
||||
CamelMessage camelMessage = (CamelMessage) message;
|
||||
CamelMessage transformedMessage = camelMessage.mapBody(new Mapper<String, String>(){
|
||||
@Override
|
||||
public String apply(String body) {
|
||||
return String.format("- %s -",body);
|
||||
}
|
||||
});
|
||||
CamelMessage transformedMessage =
|
||||
camelMessage.mapBody(new Mapper<String, String>(){
|
||||
@Override
|
||||
public String apply(String body) {
|
||||
return String.format("- %s -",body);
|
||||
}
|
||||
});
|
||||
producer.forward(transformedMessage, getContext());
|
||||
} else
|
||||
unhandled(message);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue