本文整理匯總了Java中org.apache.camel.impl.DefaultCamelContext.stop方法的典型用法代碼示例。如果您正苦於以下問題:Java DefaultCamelContext.stop方法的具體用法?Java DefaultCamelContext.stop怎麽用?Java DefaultCamelContext.stop使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.camel.impl.DefaultCamelContext
的用法示例。
在下文中一共展示了DefaultCamelContext.stop方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: runCafeRouteDemo
import org.apache.camel.impl.DefaultCamelContext; //導入方法依賴的package包/類
public void runCafeRouteDemo() throws Exception {
// create CamelContext
DefaultCamelContext camelContext = new DefaultCamelContext();
camelContext.setRegistry(createRegistry());
camelContext.addRoutes(this);
camelContext.start();
ProducerTemplate template = camelContext.createProducerTemplate();
Order order = new Order(2);
order.addItem(DrinkType.ESPRESSO, 2, true);
order.addItem(DrinkType.CAPPUCCINO, 4, false);
order.addItem(DrinkType.LATTE, 4, false);
order.addItem(DrinkType.MOCHA, 2, false);
template.sendBody("direct:cafe", order);
Thread.sleep(6000);
camelContext.stop();
}
示例2: testThirdCamelContext
import org.apache.camel.impl.DefaultCamelContext; //導入方法依賴的package包/類
@Test
public void testThirdCamelContext() throws Exception {
camel1.stop();
camel2.stop();
DefaultCamelContext camel3 = new DefaultCamelContext();
camel3.setName("camel-3");
camel3.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("quartz2://myThirdGroup/myThirdTimerName?cron=0/1+*+*+*+*+?").to("mock:three");
}
});
camel3.start();
MockEndpoint mock3 = camel3.getEndpoint("mock:three", MockEndpoint.class);
mock3.expectedMinimumMessageCount(2);
mock3.assertIsSatisfied();
camel3.stop();
}
示例3: testRestart
import org.apache.camel.impl.DefaultCamelContext; //導入方法依賴的package包/類
/**
* Make sure a resume doesn't trigger a dupe name error.
*/
@Test
public void testRestart() throws Exception {
DefaultCamelContext camel = new DefaultCamelContext();
camel.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("quartz2://myGroup/myTimerName?cron=0/1+*+*+*+*+?").to("log:one", "mock:one");
}
});
// traverse a litany of states
camel.start();
Thread.sleep(100);
camel.suspend();
Thread.sleep(100);
camel.resume();
Thread.sleep(100);
camel.stop();
Thread.sleep(100);
camel.start();
Thread.sleep(100);
camel.stop();
}
示例4: camelContextFactoryServiceRegistryTest
import org.apache.camel.impl.DefaultCamelContext; //導入方法依賴的package包/類
@Test
public void camelContextFactoryServiceRegistryTest() throws Exception {
DefaultCamelContext context = new OsgiDefaultCamelContext(getBundleContext());
context.start();
MyService myService = context.getRegistry().lookupByNameAndType(MyService.class.getName(), MyService.class);
assertNotNull("MyService should not be null", myService);
myService = context.getRegistry().lookupByNameAndType("test", MyService.class);
assertNull("We should not get the MyService Object here", myService);
Object service = context.getRegistry().lookupByName(MyService.class.getName());
assertNotNull("MyService should not be null", service);
assertTrue("It should be the instance of MyService ", service instanceof MyService);
Map<String, MyService> collection = context.getRegistry().findByTypeWithName(MyService.class);
assertNotNull("MyService should not be null", collection);
assertNotNull("There should have one MyService.", collection.get(MyService.class.getName()));
Set<MyService> collection2 = context.getRegistry().findByType(MyService.class);
assertNotNull("MyService should not be null", collection2);
assertEquals(1, collection2.size());
context.stop();
}
示例5: testThirdCamelContext
import org.apache.camel.impl.DefaultCamelContext; //導入方法依賴的package包/類
@Test
public void testThirdCamelContext() throws Exception {
camel1.stop();
camel2.stop();
DefaultCamelContext camel3 = new DefaultCamelContext();
camel3.setName("camel-3");
camel3.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("quartz://myThirdGroup/myThirdTimerName?cron=0/1+*+*+*+*+?").to("mock:three");
}
});
camel3.start();
MockEndpoint mock3 = camel3.getEndpoint("mock:three", MockEndpoint.class);
mock3.expectedMinimumMessageCount(2);
mock3.assertIsSatisfied();
camel3.stop();
}
示例6: testRestart
import org.apache.camel.impl.DefaultCamelContext; //導入方法依賴的package包/類
/**
* Make sure a resume doesn't trigger a dupe name error.
*/
@Test
public void testRestart() throws Exception {
DefaultCamelContext camel = new DefaultCamelContext();
camel.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("quartz://myGroup/myTimerName?cron=0/1+*+*+*+*+?").to("log:one", "mock:one");
}
});
// traverse a litany of states
camel.start();
Thread.sleep(100);
camel.suspend();
Thread.sleep(100);
camel.resume();
Thread.sleep(100);
camel.stop();
Thread.sleep(100);
camel.start();
Thread.sleep(100);
camel.stop();
}
示例7: shouldNotBreakRedeliveriesOfSecondContextAfterFirstBeingStopped
import org.apache.camel.impl.DefaultCamelContext; //導入方法依賴的package包/類
@Test
public void shouldNotBreakRedeliveriesOfSecondContextAfterFirstBeingStopped() throws Exception {
DefaultCamelContext context1 = createContext();
ProducerTemplate producer1 = context1.createProducerTemplate();
ConsumerTemplate consumer1 = context1.createConsumerTemplate();
context1.start();
producer1.sendBody("seda://input", "Hey1");
Exchange ex1 = consumer1.receive("seda://output", 5000);
DefaultCamelContext context2 = createContext();
ProducerTemplate producer2 = context2.createProducerTemplate();
ConsumerTemplate consumer2 = context2.createConsumerTemplate();
context2.start();
// now stop 1, and see that 2 is still working
consumer1.stop();
producer1.stop();
context1.stop();
producer2.sendBody("seda://input", "Hey2");
Exchange ex2 = consumer2.receive("seda://output", 5000);
Assert.assertNotNull(ex1);
Assert.assertEquals("Hey1", ex1.getIn().getBody());
Assert.assertNotNull(ex2);
Assert.assertEquals("Hey2", ex2.getIn().getBody());
consumer2.stop();
producer2.stop();
context2.stop();
}
示例8: testProducer
import org.apache.camel.impl.DefaultCamelContext; //導入方法依賴的package包/類
public void testProducer() throws Exception {
// use shutdown hook to verify that we have stopped within 5 seconds
Thread hook = new AssertShutdownHook();
Runtime.getRuntime().addShutdownHook(hook);
start = System.currentTimeMillis();
context = new DefaultCamelContext();
context.addRoutes(createRouteBuilder());
context.start();
sendMessage();
context.stop();
}
示例9: sendMessage
import org.apache.camel.impl.DefaultCamelContext; //導入方法依賴的package包/類
public void sendMessage() throws Exception {
DefaultCamelContext context = new DefaultCamelContext();
final CountDownLatch logonLatch = new CountDownLatch(4);
final CountDownLatch receivedMessageLatch = new CountDownLatch(1);
RouteBuilder routes = new RouteBuilder() {
@Override
public void configure() throws Exception {
// Release latch when session logon events are received
// We expect four logon events (four sessions)
from("quickfix:examples/gateway.cfg").
filter(header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.SessionLogon)).
bean(new CountDownLatchDecrementer("logon", logonLatch));
// Dynamic router -- Uses FIX DeliverTo tags
from("quickfix:examples/gateway.cfg").
filter(header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.AppMessageReceived)).
recipientList(method(new FixMessageRouter("quickfix:examples/gateway.cfg")));
// Logger app messages as JSON
from("quickfix:examples/gateway.cfg").
filter(PredicateBuilder.or(
header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.AppMessageReceived),
header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.AppMessageSent))).
bean(new QuickfixjMessageJsonPrinter());
// If the [email protected] session receives an email then release the latch
from("quickfix:examples/gateway.cfg?sessionID=FIX.4.2:[email protected]>GATEWAY").
filter(PredicateBuilder.and(
header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.AppMessageReceived),
header(QuickfixjEndpoint.MESSAGE_TYPE_KEY).isEqualTo(MsgType.EMAIL))).
bean(new CountDownLatchDecrementer("message", receivedMessageLatch));
}
};
context.addRoutes(routes);
LOG.info("Starting Camel context");
context.start();
// This is not strictly necessary, but it prevents the need for session
// synchronization due to app messages being sent before being logged on
if (!logonLatch.await(5, TimeUnit.SECONDS)) {
throw new IllegalStateException("Logon did not complete");
}
String gatewayUri = "quickfix:examples/gateway.cfg?sessionID=FIX.4.2:[email protected]>GATEWAY";
Endpoint gatewayEndpoint = context.getEndpoint(gatewayUri);
Producer producer = gatewayEndpoint.createProducer();
Email email = TestSupport.createEmailMessage("Dynamic Routing Example");
email.getHeader().setString(DeliverToCompID.FIELD, "[email protected]");
LOG.info("Sending routed message");
Exchange exchange = producer.createExchange(ExchangePattern.InOnly);
exchange.getIn().setBody(email);
producer.process(exchange);
if (!receivedMessageLatch.await(5, TimeUnit.SECONDS)) {
throw new IllegalStateException("Message did not reach target");
}
LOG.info("Message received, shutting down Camel context");
context.stop();
LOG.info("Dynamic routing example complete");
}
示例10: sendMessage
import org.apache.camel.impl.DefaultCamelContext; //導入方法依賴的package包/類
public void sendMessage() throws Exception {
DefaultCamelContext context = new DefaultCamelContext();
context.addComponent("trade-executor", new TradeExecutorComponent());
final CountDownLatch logonLatch = new CountDownLatch(2);
final CountDownLatch executionReportLatch = new CountDownLatch(2);
RouteBuilder routes = new RouteBuilder() {
@Override
public void configure() throws Exception {
// Release latch when session logon events are received
from("quickfix:examples/inprocess.cfg").
filter(header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.SessionLogon)).
bean(new CountDownLatchDecrementer("logon", logonLatch));
from("quickfix:examples/inprocess.cfg?sessionID=FIX.4.2:MARKET->TRADER").
filter(header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.AppMessageReceived)).
to("trade-executor:market");
from("trade-executor:market").to("quickfix:examples/inprocess.cfg");
// Logger app messages as JSON
from("quickfix:examples/inprocess.cfg").
filter(PredicateBuilder.or(
header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.AppMessageReceived),
header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.AppMessageSent))).
bean(new QuickfixjMessageJsonPrinter());
// Release latch when trader receives execution report
from("quickfix:examples/inprocess.cfg?sessionID=FIX.4.2:TRADER->MARKET").
filter(PredicateBuilder.and(
header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.AppMessageReceived),
header(QuickfixjEndpoint.MESSAGE_TYPE_KEY).isEqualTo(MsgType.EXECUTION_REPORT))).
bean(new CountDownLatchDecrementer("execution report", executionReportLatch));
}
};
context.addRoutes(routes);
LOG.info("Starting Camel context");
context.start();
// This is not strictly necessary, but it prevents the need for session
// synchronization due to app messages being sent before being logged on
if (!logonLatch.await(5, TimeUnit.SECONDS)) {
throw new IllegalStateException("Logon did not complete");
}
String gatewayUri = "quickfix:examples/inprocess.cfg?sessionID=FIX.4.2:TRADER->MARKET";
Endpoint gatewayEndpoint = context.getEndpoint(gatewayUri);
Producer producer = gatewayEndpoint.createProducer();
LOG.info("Sending order");
NewOrderSingle order = createNewOrderMessage();
Exchange exchange = producer.createExchange(ExchangePattern.InOnly);
exchange.getIn().setBody(order);
producer.process(exchange);
if (!executionReportLatch.await(5, TimeUnit.SECONDS)) {
throw new IllegalStateException("Did not receive execution reports");
}
LOG.info("Message received, shutting down Camel context");
context.stop();
LOG.info("Order execution example complete");
}
示例11: sendMessage
import org.apache.camel.impl.DefaultCamelContext; //導入方法依賴的package包/類
public void sendMessage() throws Exception {
DefaultCamelContext context = new DefaultCamelContext();
final CountDownLatch logonLatch = new CountDownLatch(2);
final CountDownLatch receivedMessageLatch = new CountDownLatch(1);
RouteBuilder routes = new RouteBuilder() {
@Override
public void configure() throws Exception {
// Release latch when session logon events are received
// We expect two events, one for the trader session and one for the market session
from("quickfix:examples/inprocess.cfg").
filter(header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.SessionLogon)).
bean(new CountDownLatchDecrementer("logon", logonLatch));
// For all received messages, print the JSON-formatted message to stdout
from("quickfix:examples/inprocess.cfg").
filter(PredicateBuilder.or(
header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.AdminMessageReceived),
header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.AppMessageReceived))).
bean(new QuickfixjMessageJsonPrinter());
// If the market session receives an email then release the latch
from("quickfix:examples/inprocess.cfg?sessionID=FIX.4.2:MARKET->TRADER").
filter(header(QuickfixjEndpoint.MESSAGE_TYPE_KEY).isEqualTo(MsgType.EMAIL)).
bean(new CountDownLatchDecrementer("message", receivedMessageLatch));
}
};
context.addRoutes(routes);
LOG.info("Starting Camel context");
context.start();
if (!logonLatch.await(5L, TimeUnit.SECONDS)) {
throw new IllegalStateException("Logon did not succeed");
}
String marketUri = "quickfix:examples/inprocess.cfg?sessionID=FIX.4.2:TRADER->MARKET";
Producer producer = context.getEndpoint(marketUri).createProducer();
Email email = TestSupport.createEmailMessage("Example");
Exchange exchange = producer.createExchange(ExchangePattern.InOnly);
exchange.getIn().setBody(email);
producer.process(exchange);
if (!receivedMessageLatch.await(5L, TimeUnit.SECONDS)) {
throw new IllegalStateException("Message did not reach market");
}
LOG.info("Message received, shutting down Camel context");
context.stop();
LOG.info("Example complete");
}
示例12: run
import org.apache.camel.impl.DefaultCamelContext; //導入方法依賴的package包/類
public void run() throws Exception {
DefaultCamelContext context = new DefaultCamelContext();
final CountDownLatch logoutLatch = new CountDownLatch(1);
RouteBuilder routes = new RouteBuilder() {
@Override
public void configure() throws Exception {
// Modify the outgoing logon message to add a password
// The modified message will be sent from the FIX engine when the message exchange completes
from("quickfix:examples/inprocess.cfg?sessionID=FIX.4.2:TRADER->MARKET").
filter(PredicateBuilder.and(
header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.AdminMessageSent),
header(QuickfixjEndpoint.MESSAGE_TYPE_KEY).isEqualTo(MsgType.LOGON))).
bean(new CredentialInjector("PASSWORD"));
// Release latch when the trader received a logout message
from("quickfix:examples/inprocess.cfg?sessionID=FIX.4.2:TRADER->MARKET").
filter(header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.SessionLogoff)).
bean(new CountDownLatchDecrementer("logout", logoutLatch));
// Reject all logons on market side
// Demonstrates how to validate logons
from("quickfix:examples/inprocess.cfg?sessionID=FIX.4.2:MARKET->TRADER").
filter(PredicateBuilder.and(
header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.AdminMessageReceived),
header(QuickfixjEndpoint.MESSAGE_TYPE_KEY).isEqualTo(MsgType.LOGON))).
bean(new LogonAuthenticator());
}
};
context.addRoutes(routes);
LOG.info("Starting Camel context");
context.start();
if (!logoutLatch.await(5L, TimeUnit.SECONDS)) {
throw new IllegalStateException("Logout was not received");
}
context.stop();
LOG.info("Example complete");
}
示例13: testDoesNotGetThroughFilter
import org.apache.camel.impl.DefaultCamelContext; //導入方法依賴的package包/類
@Test
public void testDoesNotGetThroughFilter() throws Exception {
final String sqsURI = String.format("aws-sqs://MyQueue?amazonSQSClient=#amazonSQSClient"
// note we will NOT delete if this message gets filtered out
+ "&deleteIfFiltered=false"
+ "&defaultVisibilityTimeout=1");
AmazonSQSClientMock clientMock = new AmazonSQSClientMock();
populateMessages(clientMock);
SimpleRegistry registry = new SimpleRegistry();
DefaultCamelContext ctx = new DefaultCamelContext(registry);
ctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from(sqsURI)
// try to filter using a non-existent header... should not go through
.filter(simple("${header.login} == true"))
.to("mock:result");
}
});
MockEndpoint result = MockEndpoint.resolve(ctx, "mock:result");
clientMock.setScheduler(ctx.getExecutorServiceManager().newScheduledThreadPool(clientMock, "ClientMock Scheduler", 1));
registry.put("amazonSQSClient", clientMock);
result.expectedMessageCount(0);
ctx.start();
// we shouldn't get
assertIsSatisfied(2000, TimeUnit.MILLISECONDS);
// however, the message should not be deleted, that is, it should be left on the queue
String response = ctx.createConsumerTemplate().receiveBody(sqsURI, 5000, String.class);
assertEquals(response, "Message: hello, world!");
ctx.stop();
clientMock.shutdown();
}
示例14: testGetThroughFilter
import org.apache.camel.impl.DefaultCamelContext; //導入方法依賴的package包/類
@Test
public void testGetThroughFilter() throws Exception {
final String sqsURI = String.format("aws-sqs://MyQueue?amazonSQSClient=#amazonSQSClient"
// note we will NOT delete if this message gets filtered out, but if it goes
// through filter, it should be deleted!
+ "&deleteIfFiltered=false"
+ "&defaultVisibilityTimeout=1");
AmazonSQSClientMock clientMock = new AmazonSQSClientMock();
populateMessages(clientMock);
SimpleRegistry registry = new SimpleRegistry();
DefaultCamelContext ctx = new DefaultCamelContext(registry);
ctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from(sqsURI)
.setHeader("login", constant(true))
// this filter should allow the message to pass..
.filter(simple("${header.login} == true"))
.to("mock:result");
}
});
MockEndpoint result = MockEndpoint.resolve(ctx, "mock:result");
registry.put("amazonSQSClient", clientMock);
clientMock.setScheduler(ctx.getExecutorServiceManager().newScheduledThreadPool(clientMock, "ClientMock Scheduler", 1));
result.expectedMessageCount(1);
ctx.start();
// the message should get through filter and mock should assert this
assertIsSatisfied(2000, TimeUnit.MILLISECONDS);
// however, the message should not be deleted, that is, it should be left on the queue
String response = ctx.createConsumerTemplate().receiveBody(sqsURI, 5000, String.class);
assertNull(response);
ctx.stop();
clientMock.shutdown();
}