gpt4 book ai didi

java - 我怎样才能以最少的依赖启动 Mule 3 embedded?

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:15:03 31 4
gpt4 key购买 nike

我希望以最少的外部依赖性(无 Spring 等)启动嵌入的 mule 3。任何有关如何操作的提示都将不胜感激。谢谢。

最佳答案

以下示例创建了一个带有入站 VM 端点和字符串附加转换器的流。我相信它应该能让您入门。

    MuleContext context = new DefaultMuleContextFactory().createMuleContext();
MuleRegistry registry = context.getRegistry();

EndpointBuilder testEndpointBuilder = new EndpointURIEndpointBuilder("vm://testFlow.in",
context);
testEndpointBuilder.setExchangePattern(MessageExchangePattern.REQUEST_RESPONSE);
registry.registerEndpointBuilder("testFlow.in", testEndpointBuilder);

InboundEndpoint vmInboundEndpoint = testEndpointBuilder.buildInboundEndpoint();
registry.registerEndpoint(vmInboundEndpoint);

StringAppendTransformer stringAppendTransformer = new StringAppendTransformer(" world");
stringAppendTransformer.setMuleContext(context);

Flow testFlow = new Flow("testFlow", context);
testFlow.setMessageSource(vmInboundEndpoint);
testFlow.setMessageProcessors(Arrays.asList((MessageProcessor) stringAppendTransformer));
registry.registerFlowConstruct(testFlow);

context.start();

MuleClient muleClient = new MuleClient(context);
MuleMessage response = muleClient.send("vm://testFlow.in", "hello", null);
Validate.isTrue(response.getPayloadAsString().equals("hello world"));

muleClient.dispose();
context.stop();

关于java - 我怎样才能以最少的依赖启动 Mule 3 embedded?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9160703/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com