I am new to apache camel.
I want to create a service bus (middle ware) using apache camel by making a jetty Post request and then get the response from the server.
Here is what I've done
<route streamCache="true">
<from uri="jetty:{{wrapperEntry.protocol}}://{{wrapperEntry.host}}:{{wrapperEntry.port}}/rsb/SubmitNewCaseForAndroid?continuationTimeout=0" />
<convertBodyTo type="java.lang.String" />
<to uri="direct:helloworld"/>
</route>
<route streamCache="true">
<from uri="direct:helloworld"/>
<transform>
<simple>
Hello World
</simple>
</transform>
<convertBodyTo type="java.lang.String" />
</route>
the request goes successfully to the server and submit my case, other wise I cannot get the response back from the server.
Note: the response comes from the is the server is string it comes like this
'code':0,
'description':'operation completed succrssfully',
'complaintId':'45285'
Thank in Advacnce
Related
I have a mock endpoint at 8001 that will echo anything provided to it.
I have an http endpoint that will submit the end of the URL to the mock endpoint, and provide a response from the endpoint's response.
That works fine.
The challenge is, I want the http route to use only 1 tcp connection to the 8001 endpoint.
I created a worker group as explained elsewhere, and set the worker count to 1. Looking through the source code, I'm thinking this approach should work.
However, when I do this bash command:
for a in {1..5}; do curl "http://localhost:8080/upstream/REQUESTNUM$a" > $a.txt & done;
I see multiple connections to 8001. I would have expected the http endpoint requests would have to share a single pool worker, but that doesn't seem to be the case.
Perhaps I am missing something, or perhaps there is another way to accomplish my goal of using only 1 back-end tcp connection for all the http requests.
How do I accomplish it?
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<camelContext
xmlns="http://camel.apache.org/schema/spring">
<route id="mockUpstream">
<from
uri="netty4:tcp://localhost:8001?sync=true&textline=true&keepAlive=true&disconnect=false&reuseChannel=true" />
<log message="Incoming to upstream: ${body}" />
<transform>
<simple>${body}</simple>
</transform>
</route>
<route id="httpServer">
<from
uri="netty4-http:http://0.0.0.0:8080/upstream?matchOnUriPrefix=true" />
<!-- optional just use CamelHttpQuery from header, for full query -->
<log
message="Incoming http command: ${in.headers[CamelHttpPath]}" />
<transform>
<simple>${in.headers[CamelHttpPath]}</simple>
</transform>
<to
uri="netty4:tcp://localhost:8001?workerGroup=#sharedPool&sync=true&textline=true&keepAlive=true&disconnect=false&reuseChannel=true" />
<transform>
<simple>${body}</simple>
</transform>
</route>
</camelContext>
<bean id="poolBuilder"
class="org.apache.camel.component.netty4.NettyWorkerPoolBuilder">
<property name="workerCount" value="1" />
</bean>
<bean id="sharedPool" class="io.netty.channel.EventLoopGroup"
factory-bean="poolBuilder" factory-method="build"
destroy-method="shutdown">
</bean>
</beans>
Looking at the logs, with TRACE level logging, I saw the NettyProducer's pool was indeed set to use 1 max active connection, but the NettyProducer was allowed 100 idle connections. I changed the following line and it is now behaving as expected:
<to
uri="netty4:tcp://localhost:8001?workerGroup=#sharedPool&sync=true&textline=true&keepAlive=true&disconnect=false&reuseChannel=true&producerPoolMaxActive=1&producerPoolMaxIdle=1" />
I assumed the "producer" settings were only good for the producer side (netty in mock host route) of the connection, but it looks like they can be used by the consumer end (netty in http route), too.
edit: I confused the terms producer and consumer and got that backwards above. Seeing that the "to" element is producing a request for something to consume, the producer* parameters make sense for (netty in http route). The (netty in mock host route) is the consumer of requests.
I'm facing connection refused exception while trying to connect through TCP even in localhost by using camel-netty4.
<route id="test-producer">
<from uri="quartz://{{t1tos.promis.containerupdate.job.detail}}" />
<to uri="bean:haSessionProcessor?method=getHAStatus" />
<log message="Server Status ::: ${body}"/>
<to uri="netty4:tcp://localhost:9001??textline=true&sync=true"/>
<log message="Server Status ::: ${body}"/>
</route>
<route id="test-consumer">
<from uri="netty4:tcp://localhost:9001clientMode=true&sync=true&textline=true"/>
<log message="Invert Server Status ::: ${body}"/>
</route>
Please advice to resolve the issue, I'm not able to find a working example for this. Do I need to configure host address and port number.
Thank you in advance.
Can you please give me possible solution to fix below problem.
Problem is internal jaxws endpoint should not visible on the bowser, when we browse context path(ex: http://localhost:8080/cws-finance/services).
service name is PaymentWs. PaymentWs service has two version’s(1.1,1.2) of wsdls.
We created two external cxf endpoints and one jaxws internal end point.
First external endpoint interact with 1.1 version wsdl and second external endpoint interact with 1.2 version wsdl
Internal jaxws endpoint interact with java code(serviceImpl)
We are using camel routing to route external endpoints to internal endpoint.
If I browse context path(ex: http://localhost:8080/cws-finance/services). I can view two are external endpoints and one is internal endpoint on the browser.
As per requirement , internal endpoint should not view on the browser. Only two external endpoints should be visible.
I am doing migration from service mix bundle to web application(war) deploying in tomcat. In servicemix ,it was working as per requirement. This requirement was achieved in servicemix by using NMR api with JBI container.
Internal jaxws endpoint configuration:
<jaxws:endpoint id="paymentWS" implementor="#paymentWSImp"
endpointName="tns:PaymentWSPort" address="/nmr/PaymentWS/1.2/Port"
serviceName="tns:PaymentWSService" xmlns:tns="http://www.centurytel.com/PaymentWS">
<jaxws:features>
<bean class="org.apache.cxf.feature.LoggingFeature" />
</jaxws:features>
<jaxws:properties>
<entry key="schema-validation-enabled" value="true" />
</jaxws:properties>
</jaxws:endpoint>
External cxf endpoints configurations:
<cxf:cxfEndpoint id="paymentWS_1_1" address="/PaymentWS/1.1/Port"
endpointName="s:PaymentWSPort" serviceName="s:PaymentWSService"
wsdlURL="wsdl/paymentws_1.1.wsdl" xmlns:s="http://www.centurytel.com/PaymentWS">
<cxf:properties>
<entry key="dataFormat" value="MESSAGE" />
</cxf:properties>
</cxf:cxfEndpoint>
<cxf:cxfEndpoint id="paymentWS_1_2" address="/PaymentWS/1.2/Port"
endpointName="s:PaymentWSPort" serviceName="s:PaymentWSService"
wsdlURL="wsdl/paymentws_1.2.wsdl" xmlns:s="http://www.centurytel.com/PaymentWS">
<cxf:properties>
<entry key="dataFormat" value="MESSAGE" />
</cxf:properties>
</cxf:cxfEndpoint>
Camel routing:
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route id="paymentWS_1_1_route">
<from uri="cxf:bean:paymentWS_1_1" />
<setExchangePattern pattern="InOut" />
<convertBodyTo type="javax.xml.transform.stream.StreamSource" />
<to uri=" http://localhost:8080/cws-finance/services /nmr/PaymentWS/1.2/Port"/>
<process ref="PaymentWS_1_1_ProxyOutProc" />
<to uri="log:input" />
</route>
<route id="paymentWS_1_2_route">
<from uri="cxf:bean:paymentWS_1_2" />
<setExchangePattern pattern="InOut" />
<convertBodyTo type="javax.xml.transform.stream.StreamSource" />
<to uri=" http://localhost:8080/cws-finance/services /nmr/PaymentWS/1.2/Port"/>
<to uri="log:input" />
</route>
</camelContext>
<route>
<from uri="file://inbox?move=.txt"/>
<to uri="netty:tcp://localhost:5150?encoders=#encoders&sync=false"/>
</route>
I need to send files to a remote legacy tcp server via a socket (IP and port ). this server is sometimes unavailable so :
1- I need to check if the remote tcp server(socket ) is available.
2- if not , i need wait 5 minutes.
I tried several options but none is working.
thanks
I made it worked with the following config :
<route id="step1" trace="false">
<from uri="file:/dev/tmp/datain/?sortBy=file:name;&delete=true&maxMessagesPerPoll=1" />
<convertBodyTo type="java.lang.String" />
<to uri="direct-vm:toTcp?block=true&timeout=10000" />
</route>
<route id="step2" trace="false">
<from uri="direct-vm:toTcp?block=true&timeout=10000" />
<to uri="netty4:tcp://localhost:7000?sync=true&textline=true&requestTimeout=50000&synchronous=true" />
</route>
I want to test camel spring integration example from the apache camel site
http://camel.apache.org/springintegration.html but I am getting the exception
org.apache.camel.RuntimeCamelException: org.springframework.integration.MessageDeliveryException: Dispatcher has no subscribers for channel outputchannel.
my short code is given below:
<channel id="inChannel"/>
<channel id="outputChannel"/>
<beans:bean id="greeting" class="com.javarticles.spring.integration.Greeting"/>
<service-activator input-channel="inChannel" ref="greeting" method="sayHello" output-channel="outputChannel"/>
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="activemq:activemqsource"/>
<to uri="log:input"/>
<to uri="spring-integration:inChannel? inputChannel=outputChannel"/>
<to uri="log:output"/>
</route>
I tried to search related problems but I did not get with camel could any one tell me how to subscribe the outputchannel
According to the Camel documentation mentioned by you, the config should be like this:
<to uri="spring-integration:inputChannel?inOut=true&inputChannel=outputChannel"/>
Your issue is inOut=true:
The exchange pattern that the Spring integration endpoint should use. If inOut=true then a reply channel is expected, either from the Spring Integration Message header or configured on the endpoint.