Iam trying to send a string message from a java program to queue in ActiveMQ using MULE.Iam new to mule this is my mule-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jms="http://www.mulesoft.org/schema/mule/jms"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tool http://www.springframework.org/schema/tool/spring-tool-3.0.xsd
http://www.mulesoft.org/schema/mule/jms http://www.mulesoft.org/schema/mule/jms/3.1/mule-jms.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.1/mule.xsd">
<jms:activemq-connector name="jmsConnector"
specification="1.1"
brokerURL="tcp://localhost:61616" />
<model name="jmsModel">
<service name="jmsService">
<inbound>
</inbound>
<outbound>
<pass-through-router>
<jms:outbound-endpoint queue="myQueue" />
</pass-through-router>
</outbound>
</service>
</model>
</mule>
and following is my java class
public class MuleCaller {
public static void main(String args[])
{
MuleCaller springCaller = new MuleCaller();
springCaller.runListner();
// spAsync.onMessage(null);
}
public void runListner(){
ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext(new String[] {
"mule-config.xml"
});
}
What are the mistakes here, and iam not clear what to be written in
Thanks and regards
This is based on an older Mule version (3.1.2) and is using flow syntax
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jms="http://www.mulesoft.org/schema/mule/jms"
xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.1/mule.xsd
http://www.mulesoft.org/schema/mule/jms http://www.mulesoft.org/schema/mule/jms/3.1/mule-jms.xsd">
<jms:activemq-connector name="jmsConnector"
brokerURL="tcp://localhost:61616"
specification="1.1"
maxRedelivery="30"
disableTemporaryReplyToDestinations="true"
createMultipleTransactedReceivers="true"
acknowledgementMode="CLIENT_ACKNOWLEDGE"
numberOfConcurrentTransactedReceivers="1"
persistentDelivery="true">
</jms:activemq-connector>
<flow name="inbound JMS service">
<jms:inbound-endpoint connector-ref="jmsConnector" queue="/jmsQueue" exchange-pattern="one-way">
<jms:transaction action="BEGIN_OR_JOIN"/>
</jms:inbound-endpoint>
<echo-component/>
</flow>
Using the ActiveMQ console you can create a queue called jmsQueue and manually send messages to it. A Mule process using the config above should print out whatever text is in the message you place on the queue.
Firstly, there is a connector-ref attribute of the jms:outbound-endpoint tag that you should likely use to specific to where outbound messages are to go.
like this:
<jms:outbound-endpoint connector-ref="jmsConnection" queue="myQueue" />
Secondly, without an inbound route, i've no clue what data is to be operated on by your service. try to go through some more of the example.
Related
I am trying to load an Apache Camel routes at runtime and add to existing CamelContext. I have route defined like below ,
<?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">
<routeContext id="message" xmlns="http://camel.apache.org/schema/spring">
<route id="abcRoute" autoStartup="false">
<from uri="activemq:input"/>
<delay>
<constant>1000</constant>
</delay>
<to uri="activemq:output"/>
</route>
</routeContext>
</beans>
I see , it was passible to load camel routes at runtime using loadRoutesDefinition in camel2 as below ,
InputStream inputStream = getClass().getResourceAsStream("MyRoute.xml");
RoutesDefinition routesDefinition = camelContext.loadRoutesDefinition(is);
camelContext.addRouteDefinitions(routesDefinition.getRoutes());
I am looking for possible way to load camel routes in camel3 at runtime.
You can load route definitions from files by using ExtendedCamelContext, adapting your Camel context:
ExtendedCamelContext ecc = camelContext.adapt(ExtendedCamelContext.class);
Resource resource = ResourceHelper.fromBytes("resource.xml", bytes);
ecc.getRoutesLoader().loadRoutes(resource);
where bytes is the byte array that stores the content of your file.
We are initializing the 2 different camel routes via spring context xml,
<?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-2.0.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<camelContext id="camelContext" xmlns="http://camel.apache.org/schema/spring">
<routeBuilder ref="DescriptiveInfoRoute"/>
<routeBuilder ref="DescriptiveInfoRouteV2"/>
</camelContext>
</beans>
Both the routes are separate each will having it's input properties files to read the input values. (which makes 2 input files should be compulsory in order for both the routes to get initialized and starts the application). Now we got a new requirement one input file may or may not present. So is there any way in the spring to successfully start the application even if one the route was successfully initialized.
Thanks in advance,
Raghavan
I have a context as follows
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-amqp="http://www.springframework.org/schema/integration/amqp"
xmlns:rabbit="http://www.springframework.org/schema/rabbit"
xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/amqp
http://www.springframework.org/schema/integration/amqp/spring-integration-amqp.xsd
http://www.springframework.org/schema/rabbit
http://www.springframework.org/schema/rabbit/spring-rabbit.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<int:gateway id="fooGateway" service-interface="com.foo.FooGateway" />
</beans>
My gateway interface is as follows:
public interface FooGateway
{
public void foo(String foo);
}
This context is imported into another context but the fooGateway bean is never created by GatewayProxyFactoryBean.
I've set a breakpoint in GatewayProxyFactoryBean and I can see that it is not creating a proxy for this interface.
Turn on DEBUG logging for org.springframework; the bean creation process emits lots of information including when it reads particular configuration files.
I am trying to get the basic http rest helloworld example working in Mule but I get this error
Could not find a transformer to transform "SimpleDataType{type=java.lang.String, mimeType='*/*'}" to "SimpleDataType{type=java.io.InputStream, mimeType='*/*'}". (org.mule.api.transformer.TransformerException). Message payload is of type: String
This is my config file:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" xmlns:jersey="http://www.mulesoft.org/schema/mule/jersey"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.3/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/3.3/mule-http.xsd
http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/3.3/mule-xml.xsd
http://www.mulesoft.org/schema/mule/jersey http://www.mulesoft.org/schema/mule/jersey/3.0/mule-jersey.xsd
http://jersey.apache.org/core http://jersey.apache.org/schemas/core.xsd">
<flow name="HelloWorld">
<inbound-endpoint address="http://localhost:8081/api"/>
<jersey:resources>
<component class="com.helloworld.AdminApi"/>
</jersey:resources>
</flow>
</mule>
And my jersey service class
#Path("version")
public class AdminApi {
#GET
#Produces("text/plain")
public String sayHelloWithUri() {
return "Version 999 " ;
}
}
I am trying to access the service using:
http://localhost:8081/api/version
which I believe should be the right url but no luck I always get the above exception message.
Anyone has an idea what this could be?
EDIT:
Root Exception stack trace:
org.mule.api.registry.ResolverException: There are two transformers that are an exact match for input: "class java.lang.String", output: "class java.io.InputStream". Transformers are: "_ObjectToInputStream(class org.mule.transformer.simple.ObjectToInputStream)" and "_ObjectToInputStream(class org.mule.transformer.simple.ObjectToInputStream)"
at org.mule.transformer.graph.GraphTransformerResolver.resolve(GraphTransformerResolver.java:65)
at org.mule.registry.TypeBasedTransformerResolver.resolve(TypeBasedTransformerResolver.java:93)
at org.mule.registry.MuleRegistryHelper.resolveTransformer(MuleRegistryHelper.java:265)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
Your configuration runs just fine with Mule 3.3.0 (tested outside of Tomcat, in Eclipse) so I suspect the problem comes from either missing or duplicated JARs on your web application classpath.
Check the JARs that get packaged in WEB-INF/lib and potential manually added JARs in Tomcat's /lib directory.
<flow name="HelloWorld">
<inbound-endpoint address="http://localhost:8081/api"/>
<jersey:resources>
<component class="com.helloworld.AdminApi"/>
</jersey:resources>
</flow>
and use this url. http://localhost:8081/api/version
result is -Version 999
If you are running with Mule Studio 3.3.0, you must put the mimeType.
Example:
<flow name="RestServiceFlow" doc:name="RestServiceFlow">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8083" doc:name="HTTP" mimeType="application/json"/>
<jersey:resources doc:name="RESTUTCNotification">
<component class="example.esb.restApi"/>
</jersey:resources>
</flow>
I am using Spring 3.1.1 with mule.
The versions of the jars used inside mule are 3.1.1 RELEASE.
Inside my configuration XML which is a mule flow,
I am getting following SAX parser exception.
Caused by: org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting with element 'context:component-scan'. One of '{"http://www.mulesoft.org/schema/mule/core":annotations, "http://www.mulesoft.org/schema/mule/core":description, "http://www.springframework.org/schema/beans":beans, "http://www.springframework.org/schema/beans":bean, "http://www.springframework.org/schema/context":property-placeholder, "http://www.springframework.org/schema/beans":ref, "http://www.mulesoft.org/schema/mule/core":global-property, "http://www.mulesoft.org/schema/mule/core":configuration, "http://www.mulesoft.org/schema/mule/core":notifications, "http://www.mulesoft.org/schema/mule/core":abstract-extension, "http://www.mulesoft.org/schema/mule/core":abstract-mixed-content-extension, "http://www.mulesoft.org/schema/mule/core":abstract-agent, "http://www.mulesoft.org/schema/mule/core":abstract-security-manager, "http://www.mulesoft.org/schema/mule/core":abstract-transaction-manager, "http://www.mulesoft.org/schema/mule/core":abstract-connector, "http://www.mulesoft.org/schema/mule/core":abstract-global-endpoint, "http://www.mulesoft.org/schema/mule/core":abstract-exception-strategy, "http://www.mulesoft.org/schema/mule/core":abstract-flow-construct, "http://www.mulesoft.org/schema/mule/core":flow, "http://www.mulesoft.org/schema/mule/core":sub-flow, "http://www.mulesoft.org/schema/mule/core":abstract-model, "http://www.mulesoft.org/schema/mule/core":abstract-interceptor-stack, "http://www.mulesoft.org/schema/mule/core":abstract-filter, "http://www.mulesoft.org/schema/mule/core":abstract-transformer, "http://www.mulesoft.org/schema/mule/core":processor-chain, "http://www.mulesoft.org/schema/mule/core":custom-processor, "http://www.mulesoft.org/schema/mule/core":invoke, "http://www.mulesoft.org/schema/mule/core":abstract-global-intercepting-message-processor, "http://www.mulesoft.org/schema/mule/core":custom-queue-store, "http://www.mulesoft.org/schema/mule/core":abstract-processing-strategy}' is expected.
My mule flow is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:jms="http://www.mulesoft.org/schema/mule/jms" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:core="http://www.mulesoft.org/schema/mule/core" version="CE-3.3.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/jms http://www.mulesoft.org/schema/mule/jms/current/mule-jms.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<context:component-scan base-package="com.comviva.mfs.eig.logging.dataAccess" />
<jms:activemq-connector name="Active_MQ" brokerURL="tcp://localhost:61616" validateConnections="true" doc:name="Active MQ"/>
I made sure that both xsi:schemaLocation and xmlns:context are declared.
Cannot figure out why sax parser exception is occurring.
Please Help me out.
Update:
Any Solution to Separate both the XML files will also work for me.
Please help me how to maintain separate ApplicationContext.xml for spring in our mule application.
I think you cannot use <context:component-scan> as a direct child of <mule>. Try the following:
<mule ...>
<spring:beans>
<context:component-scan ... />
</spring:beans>
</mule>
This is answer for the Update part of your question:
You can move <context:component-scan> alone to a new context file this way:
appnewcontext.xml:
<context:component-scan base-package="com.comviva.mfs.eig.logging.dataAccess" />
and import into the main one:
<beans:import resource="appnewcontext.xml"/>
You can ignore the resource is not defined error. That is a bug but doesn't impact your application from running.