我正在运行 servicemix 4.4.1。我正在尝试使用camel-http4 对网站进行http 调用。无论我尝试调用哪个网站,我都会收到此错误: org.apache.camel.RuntimeCamelException: org.apache.camel.component.http.HttpOperationFailedException: HTTP 操作失败调用http://servicemix.apache.org/downloads /servicemix-4.4.0.html状态代码:405
这是我的代码片段:
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="activemq://events1"/>
<setHeader headerName="CamelHttpMethod">
<constant>POST</constant>
</setHeader>
<to uri="http://servicemix.apache.org/downloads/servicemix-4.4.0.html"/>
<to uri="log:events"/>
</route>
</camelContext>
Run Code Online (Sandbox Code Playgroud)
我尝试过许多网站并尝试使用不同的 http 方法(post 与 get),但我不断收到相同的错误。任何想法?提前致谢。
我是 Apache Camel 概念的新手。我曾尝试使用 apache camel API 编写示例代码,但在尝试运行代码时出现以下异常。
谁能帮我解决这个问题?
这是示例代码和一个例外,
示例代码:
CamelContext context = new DefaultCamelContext();
context.addRoutes(new RouteBuilder() {
public void configure() {
from("direct:start")
.setHeader(Exchange.HTTP_URI,simple("`http://sample-host:8080/demo/get`"))
.to("http://emptyhost");
}
});
context.start();
ProducerTemplate template = context.createProducerTemplate();
System.out.println(template.requestBodyAndHeaders("direct:start", null, null,String.class));
Run Code Online (Sandbox Code Playgroud)
例外 :
Exception in thread "main" org.apache.camel.FailedToCreateRouteException:
Failed to create route route1 at:
>>> To[`http://sample-host:8080/demo/get`] <<<
in route: Route(route1)
[[From[direct:start]] -> [`To[http://sample-host:8`…
because of
Failed to resolve endpoint: `http://sample-host:8080/demo/get`
due to:
No component found with scheme: http
Run Code Online (Sandbox Code Playgroud) 我正在使用 apache 的 activemq 进行排队。在向队列写入内容时,我们开始经常看到以下异常:
Caused by: org.apache.activemq.transport.InactivityIOException: Cannot send, channel has already failed:
at org.apache.activemq.transport.AbstractInactivityMonitor.doOnewaySend(AbstractInactivityMonitor.java:282)
at org.apache.activemq.transport.AbstractInactivityMonitor.oneway(AbstractInactivityMonitor.java:271)
at org.apache.activemq.transport.TransportFilter.oneway(TransportFilter.java:85)
at org.apache.activemq.transport.WireFormatNegotiator.oneway(WireFormatNegotiator.java:104)
at org.apache.activemq.transport.MutexTransport.oneway(MutexTransport.java:68)
at org.apache.activemq.transport.ResponseCorrelator.asyncRequest(ResponseCorrelator.java:81)
at org.apache.activemq.transport.ResponseCorrelator.request(ResponseCorrelator.java:86)
at org.apache.activemq.ActiveMQConnection.syncSendPacket(ActiveMQConnection.java:1366)
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚是什么导致了这种情况 - 甚至坦率地说,从哪里开始调试导致这种情况的原因。
这是队列设置代码:
camelContext = new DefaultCamelContext();
camelContext.setErrorHandlerBuilder(new LoggingErrorHandlerBuilder());
camelContext.getShutdownStrategy().setTimeout(SHUTDOWN_TIMEOUT_SECONDS);
routePolicy = new RoutePolicy();
routePolicy.setCamelContext(camelContext);
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
connectionFactory.setBrokerURL(queueUri);
// use a pooled connection factory between the module and the queue
pooledConnectionFactory = new PooledConnectionFactory(connectionFactory);
// how many connections should there be in the session pool?
pooledConnectionFactory.setMaxConnections(this.maxConnections); …Run Code Online (Sandbox Code Playgroud) 当我将骆驼路由处理的集成测试作为独立测试运行时,它通过了。当我运行所有测试时,它失败并出现预期值的断言错误。当我将 @DirtiesContext 添加到抽象测试类时,它们都通过了。
我检查了文档并超出了下面的段落,他们没有说明为什么实际上需要@DirtiesContext,以及不使用时会出现什么问题。
请注意,我们在测试方法上使用@DirtiesContext来强制Spring测试在每个测试方法之后自动重新加载CamelContext - 这确保了测试不会相互冲突(例如,一个测试方法发送到一个端点,然后在另一种测试方法)。
问题是,一次又一次地创建 Spring 上下文非常耗时。我们所有其他非骆驼集成测试都在没有@DirtiesContext(使用@Transactional)的情况下通过,我们希望继续这样做。
有没有一种方法可以将camel置于原始状态而不重新创建整个spring上下文,以便测试的MockEndpoints按预期工作?
我有这样的情况:
我希望我的路线不会在大规模任务进行时重新触发。也就是说,定时器可能会发出事件,但它不应该以某种方式导致触发路由。当大量任务完成后,定时器应该可以重新开始路由。
实现这种行为的最佳方法是什么?
我面临着架构假设的问题。小背景:我正在编写一个游戏服务器,它可以为指定的玩家创建房间,并且在该房间(websocket)内,服务器正在侦听任何事件(例如玩家丢失、互联网断开等)。整体性将是可扩展的,因此将在一些 LB 监督下部署多个 Tomcat 节点。目前我已经弄清楚了这个过程(还记得关于 tomcat 集群):
客户端通过 REST API 登录到 GameServer,会话保存在所有节点之间共享的 RedisDB 中。服务器返回 HTTP 200。
客户已登录系统,他决定搜索游戏。调用“/search/game”端点。
2.1. 系统处理用户请求并将播放器添加到 RedisDB 的临时队列(下一个或同一实例现在不确定),并向客户端返回 HTTP 200。
一个特定节点上的调度程序每 10-20 秒运行一次。并查看 RedisDB 是否有任何记录,如果是真的,那么服务器会一直将玩家并列并为他们创建游戏室,直到 RedisDB 为空或有奇怪的玩家。
我不确定如何在 websocket 中并置特定的播放器并使其对其他节点可见。我用谷歌搜索了一段时间,发现了一个类似的例子
堆栈:tomcat 集群中的 Spring Websocket
用户 Thanh Nguyen Van 提到了通过多个 tomcat 实例处理 websockets 流量的两种方法,所以我决定使用 Apache ActiveMq JMS 和 Apache Camel 作为处理 websockets 流量的解决方案。
我已经在沙盒应用程序上成功实现了它,其中 3 个不同的用户可以登录系统并相互发送私人消息。整体搭配来实现ActiveMq,Camel,STOMP,SockJS和Spring Boot。很公平……但这是我坚持的部分。我觉得我已经得到了我需要的所有积木,但我不能把它们放在一起。
首先,我不确定给定的过程是否适合提出的问题。我正在考虑points 2 and 3,而不是调用REST endpoint和添加玩家RedisDB …
我正在实现与需要当前日期和时间的外部服务的集成。该服务的文档说它接受 ISO 8601 格式的日期时间,但这只是部分正确 - 它不支持时区偏移。
当我${date:now:yyyy-MM-dd'T'HH:mm:ssZ}在 Camel 中尝试时,我得到2017-08-16T21:45:10+0200,这是服务不可接受的。
有没有办法让骆驼日期格式以UTC格式输出当前日期?我想得到2017-08-16T19:45:10Z而不是2017-08-16T21:45:10+0200.
我想避免为此编写单独的 bean,所以我更喜欢纯粹在 XML DSL 中实现的解决方案。
在 Apache Camel 中,我尝试使用 XmlJsonDataFormat 进行从 XML 到 JSON 的快速转换。但是 XMLJSON ( http://camel.apache.org/xmljson.html ) 已被弃用,所以我不确定除了创建处理器之外进行这种转换的最佳方法是什么。
有谁知道 XmlJsonDataFormat 的替代方案?
我试图理解骆驼中的工作单元概念。我有一个简单的问题希望这里有人可以提供帮助。
例如,如果路由交换涉及多个路由
from("aws-sqs:Q1").to("direct:processMe");//route1
from("direct:processMe").to("direct:aws-post");//route2
from("direct:aws-post").to("htt4:myservice");//route3
Run Code Online (Sandbox Code Playgroud)
工作单元是否在每条路由结束时调用?还是只在路线 3 的末端?在我的示例中,一旦route1完成,SQS消息是否会从SQS中删除?或者它会等到我的消息到达“myservice”?
谢谢。
跟进:
我稍微修改了路线:
from("aws-sqs:Q1").to("direct:processMe");//route1
from("direct:processMe").process(
new Processor(){
public void process(Exchange exchange) throws Exception {
throw new RuntimeException("fail on purpose");
}
}
).to("direct:aws-post");//route2
from("direct:aws-post").to("http4:myservice");//route3
Run Code Online (Sandbox Code Playgroud)
思考过程是这样的:如果在每个路由末尾调用工作单元,那么一旦从 SQS 队列读取消息,SQS 组件就会确认该消息已读取。另一方面,如果仅在 Exchange 完成所有路由的路由后才调用工作单元,则路由 2 中的异常将导致消息未被确认,并且一旦可见期到期即可重新传递。
测试表明,尽管已通过第一条路线读取,该消息仍保留在 Q 上。它被一次又一次地拾取(直到它以死信 q 结束)。因此,我坚信单元边界是由路由的 Exchange 末端定义的。
我是骆驼新手。我正在 spring-boot 中做一个项目,使用camel作为路由。我注意到,当我去 SwaggerUi 查看 Post 调用的正确功能时,路由的 contextPath 不起作用:
public void configure() {
restConfiguration().component("servlet").contextPath("service/");
rest("/ocs")
.post("/homologation")
.id(camelRoutesIdConfig.getHomologationRequestRouteId())
.consumes("application/json")
.produces("application/json")
.param()
.name("IntegrationRequestDto")
.type(RestParamType.body)
.required(true)
.description("attivazione nuovo contratto sul portale")
.endParam()
.to("direct:homologation")
}
Run Code Online (Sandbox Code Playgroud)
如果在 application.yml 中我像这样指定 contextPath ,则不会出现此问题:
camel:
rest:
component: servlet
binding-mode: json
enable-cors: true
data-format-property:
prettyPrint: false
component:
servlet:
mapping:
context-path: /service/*
Run Code Online (Sandbox Code Playgroud)
当我在一种情况下拨打 Post 电话时,它可以工作,而在路线中的 ContextPath 情况下,它无法识别该命令并给出
{
"timestamp": "2020-11-22T17:44:26.701+0000",
"status": 404,
"error": "Not Found",
"message": "Not Found",
"path": "/service/ocs/homologation"
}
Run Code Online (Sandbox Code Playgroud)
为什么会出现这个问题呢?为什么我还被迫在 application.yml 中指定,而不是在路由中仅使用一次?感谢大家提供可能的答案
apache-camel ×10
java ×6
spring-boot ×2
routes ×1
spring ×1
spring-camel ×1
spring-test ×1
timer ×1
xml-to-json ×1