ActiveMQ setup of tcp socket using mina - activemq

I am trying to setup a simple demo of activemq and mina. I edited the camelContext in the activemq.xml file to include two mina tcp sockets, two queues and routes as such:
listenerA -> qA -> listenerB
listenerB -> qB -> listenerA
The intent is to have two way pass through between two telnet sessions. Later, I will add more fancy features such as filtering, routing to a topic and my own codec on each listener.
Here is my camelcontext:
<!-- You can use a <package> element for each root package to search for Java routes -->
<package>com.myco.codec</package>
<endpoint id="listener_A" uri="mina:tcp://localhost:42000?textline=true"/>
<endpoint id="listener_B" uri="mina:tcp://localhost:42001?textline=true"/>
<!-- You can use Spring XML syntax to define the routes here using the <route> element -->
<route>
<from ref="listener_A"/>
<to uri="activemq:qA"/>
</route>
<route>
<from uri="activemq:qB"/>
<to ref="listener_A"/>
</route>
<route>
<from ref="listener_B"/>
<to uri="activemq:qB"/>
</route>
<route>
<from uri="activemq:qA"/>
<to ref="listener_B"/>
</route>
</camelContext>
When I start activemq I get an exception:
org.apache.camel.NoSuchEndpointException: No endpoint could be found for: mina:tcp://localhost:42000?textline=true
Do I explicitly need to add a mina bean? If so where and how?

Do you have camel-mina.jar and the mina jars on the classpath?
Based on the thread here it seems to have fixed it.

Related

Understanding about FUSE Server and camel

New to FUSE and Camel.
Downloaded CBR project from (https://github.com/jboss-fuse/quickstarts) and was able to run it as standalone camel project.
cbr.xml is as follows. This drops MSG from a work/cbr/input directory into another. Could run this as mvn camel:run
<route id="cbr-route">
<from uri="file:work/cbr/input" />
<log message="Receiving order ${file:name}" />
<choice>
<when>
<xpath>/order:order/order:customer/order:country = 'UK'</xpath>
<log message="Sending order ${file:name} to the UK" />
<to uri="file:work/cbr/output/uk" />
</when>
<when>
<xpath>/order:order/order:customer/order:country = 'US'</xpath>
<log message="Sending order ${file:name} to the US" />
<to uri="file:work/cbr/output/us" />
</when>
<otherwise>
<log message="Sending order ${file:name} to another country" />
<to uri="file:work/cbr/output/others" />
</otherwise>
</choice>
<log message="Done processing ${file:name}" />
</route>
</camelContext>
But ReadMe says start FUSE SEVER
trying to understand why do i need FUSE container at all if i am able to run it as standlone
There is a project requirement that web service calls from Client go through FUSE for making it asynchronous.
assuming i would not need fuse container in this case
Thanks for taking the time and reading
The FUSE is the container just like any other container , say tomcat, where you deploy your code to.
If you have a lot of integration scenarios and then you need to have a dedicated server to hold and run all your deploy-able. At least that is what I would suggest.
But if there are only a few of such scenarios you can use the power of camel , being framework,use it as a supporting jar for your java code and run as a standalone code.
This means you are responsible to number of requests and issues regarding availability or scalability for that piece of integration code.

Unable to find Spring bean in Fuse Project

I'm setting the body of a Camel route using a Bean. That works on a Camel standalone project. When deployed on JBoss Fuse the Spring bean is not found. Here is a snippet of the blueprint:
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cxf="http://camel.apache.org/schema/blueprint/cxf"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://camel.apache.org/schema/blueprint/cxf http://camel.apache.org/schema/blueprint/cxf/camel-cxf.xsd
http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">
<bean id="personFactory" class="sample.PersonFactory" />
<bean id="myBean" class="sample.Person" />
<camelContext id="cbr-example-context" xmlns="http://camel.apache.org/schema/blueprint" xmlns:order="http://fusesource.com/examples/order/v7">
<route id="myroute">
<from uri="timer:foo?repeatCount=1"/>
<setProperty propertyName="name">
<constant>John</constant>
</setProperty>
<setProperty propertyName="surname">
<constant>Doe</constant>
</setProperty>
<setBody>
<spel>#{#personFactory.createPerson(properties['name'],properties['surname'])}
</spel>
</setBody>
. . . .
</route>
</camelContext>
</blueprint>
When deployed on Fuse, the following exception is raised:
org.apache.camel.ExpressionEvaluationException: org.springframework.expression.spel.SpelEvaluationException:
EL1057E:(pos 1): No bean resolver registered in the context to resolve access to bean 'personFactory'
Any help ?
I had same problem recently. Unfortunately, did not managed to resolve this using spel and have switched to simple. This should help in your case:
<simple>${bean:personFactory?method=createPerson(property.name, property.surname)}</simple>

wso2esb - Add https to my api

I have this simple example of my rest api, and now I want to add https capabilities to this resource.
<api name="API_FEETIT_VERSION" context="/api_feetit_version">
<resource methods="GET" protocol="https">
<inSequence>
<send>
<endpoint>
<address uri="http://myserver.net/version"/>
</endpoint>
</send>
</inSequence>
</resource>
To do this I just added attribute protocol="https" on resource, but now I cant access the service. Already try on port 8243 but still nothing.
Do I need to do anything else? Or even my endpoint service needs to use https too?
Yes , your backend service will need to be https as well as your endpoint address.
<address uri="https://myserver.net/version"/>
Log in to the ESB Management console.
Under "Service Bus" section/tab , click the last option "Source View".
Search(ctrl-f) for you API , then its resource , and check if protocol="https". This is one of mine:
< resource methods="POST"
protocol="https"
inSequence="ackServiceSeq"
outSequence="hcfRequest"/ >
Weird how the "invokation url" stays the same

Apache Camel Resequencer with Apache Camel SEDA queue?

I have a SEDA queue that uses the parameter "concurrentConsumers=5". Now, I am trying to integrate it with the Apache Camel Resequencer in order to be able to reorder the messages before processing them, however, when I do this, only one message is processed at a time. I would like to know if it is possible to run several resequencer messages in parallel.
This is my XML code:
<route>
<from uri="seda:barSetup?concurrentConsumers=5" />
<resequence>
<batch-config batchSize="300" batchTimeout="40000"
allowDuplicates="true"/>
<simple>in.header.priority</simple>
<to uri="exec:cat" />
<to uri="bean:batchjobMonitor" />
<to uri="log:output" />
</resequence>
</route>
I am not very familiar with queues or Camel so, sorry if this is a stupid question.
Thanks.
Finally I solved this not using the resequencer. I used the PriorityBlockingQueueFactory and in the comparator I use a similar resequencer to camel:
<bean id="priorityQueueFactory"
class="org.apache.camel.component.seda.PriorityBlockingQueueFactory">
<property name="comparator">
<bean class="com.sg.sgf.service.queues.MyExchangeComparator" />
</property>
</bean>
And then, in the route:
<route>
<from uri="seda:priority?queueFactory=#priorityQueueFactory&size=100&concurrentConsumers=5&pollTimeout=10000" />
<!-- <resequence>
<batch-config batchSize="300" batchTimeout="40000"
allowDuplicates="true" />
<simple>in.header.priority</simple> -->
<to uri="exec:cat" /> <!-- the actual executable is set in the job that is passed to the queue -->
<to uri="bean:batchjobMonitor" />
<to uri="log:output" />
<!-- </resequence> -->
</route>
With this, I have what I wanted.

Mule 3: Creating a RESTful web service endpoint

I'm trying to create an endpoint (I think that's the right word?) in Mule 3 that responds to GET requests. This Mule application runs within a JavaEE web app within a web container.
In my web.xml, I have a MuleRESTReceiverServlet servlet defined so that it handles all requests whose URLs begin with "/rest/":
<web-app>
<listener>
<listener-class>org.mule.config.builders.MuleXmlBuilderContextListener</listener-class>
</listener>
<servlet>
<servlet-name>muleRESTServlet</servlet-name>
<servlet-class>org.mule.transport.servlet.MuleRESTReceiverServlet</servlet-class>
<load-on-startup />
</servlet>
<servlet-mapping>
<servlet-name>muleRESTServlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
My <flow> looks like this:
<flow name="myFlow">
<servlet:inbound-endpoint path="category/service" />
<component>
<singleton-object class="com.company.MyComponent" />
</component>
<outbound-endpoint ... />
</flow>
When I sent a GET request to "http://localhost:8080/webappName/rest/category/service", I expect it to invoke the com.company.MyComponent class. But instead, I get the error:
org.mule.api.endpoint.MalformedEndpointException: The endpoint "service" is malformed and cannot be parsed. If this is the name of a global endpoint, check the name is correct, that the endpoint exists, and that you are using the correct configuration (eg the "ref" attribute). Note that names on inbound and outbound endpoints cannot be used to send or receive messages; use a named global endpoint instead.
I tried defining the inbound endpoint as a global endpoint like the error message seems to suggest, but I just get back the same error.
<servlet:endpoint name="myEndpoint" path="category/service" />
...
<flow name="myFlow">
<inbound-endpoint ref="myEndpoint" />
<component>
<singleton-object class="com.company.MyComponent" />
</component>
<outbound-endpoint ... />
</flow>
I've also tried setting the "path" attribute to "rest/category/service" and "/rest/category/service", but still got the same error message.
What am I doing wrong? Thanks.
The org.mule.transport.servlet.MuleRESTReceiverServlet works with a very specific path convention that allows you to directly query an existing Mule endpoint by name or path. Read the JavaDoc here.
In your case, to use servlet:inbound-endpoint, you need to use the org.mule.transport.servlet.MuleReceiverServlet.