I have a basic mule flow:
HTTP => SOAP => JAVA CLASS
<mule xmlns:cxf="http://www.mulesoft.org/schema/mule/cxf" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.6.1"
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-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/cxf http://www.mulesoft.org/schema/mule/cxf/current/mule-cxf.xsd">
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
<flow name="test_dynamicsFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
<cxf:jaxws-service doc:name="CXF"/>
<component doc:name="Java"/>
</flow>
</mule>
I would like to make a retrying connection to SOAP with timeout but I don't know if it possible.
I've been looking for error handling connectors:
Should I use these connectors to do that or how can I implement it?
You need to wrap your HTTP call with the until-successful scope.
Example:
<until-successful objectStore-ref="objectStore" maxRetries="5" secondsBetweenRetries="60" >
<http:request config-ref="HTTP_Request_Configuration" path="submit" method="POST" />
</until-successful>
Reference: https://developer.mulesoft.com/docs/display/current/Until+Successful+Scope
Related
I am writing a Functional Unit test case to test a Mule Flow containing an inbound and outbound HTTP connector. The flow contains the following components:
An inbound HTTP connector that listens to a rest service call say http://localhost:8080/restapi/id
A logger that displays the id in the logs
A web service consumer that sends the soap request to server2 at the wsdl : http://server2:8080/sample.wsdl
A java component that reads recieves the output from server2 and forms the response for client.
In the functional Unit test case, I am trying to mock the HTTP outbound connector calling the serevr2.
How can I do this?
The flow configuration file code is as below:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:ws="http://www.mulesoft.org/schema/mule/ws" xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="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-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ws http://www.mulesoft.org/schema/mule/ws/current/mule-ws.xsd
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd">
<http:request-config name="HTTP_Request_Configuration" host="server2" port="8080" doc:name="HTTP Request Configuration"/>
<ws:consumer-config name="Web_Service_Consumer" wsdlLocation="http://server2:8080/sample.wsdl" service="sample" port="sample" serviceAddress="sample" doc:name="Web Service Consumer"/>
<flow name="samplehttpflowFlow">
<http:listener config-ref="bookmartmanager-httpListenerConfig" path="/restapi/id" allowedMethods="GET" doc:name="HTTP"/>
<logger message="REST request received at #[java.lang.System.currentTimeMillis()]" level="INFO" doc:name="Logger"/>
<ws:consumer config-ref="Web_Service_Consumer" doc:name="Web Service Consumer"/>
<json:xml-to-json-transformer doc:name="XML to JSON"/>
</flow>
</mule>
Everytime I try to send an email in AnyPoint Studio I get an error. I've tried sending it from other computers and it always works. It just doesn't seem to work in mine and I have no idea why.
This is my .xml:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:smtp="http://www.mulesoft.org/schema/mule/smtp" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="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-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/smtp http://www.mulesoft.org/schema/mule/smtp/current/mule-smtp.xsd">
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
<smtp:gmail-connector name="Gmail" validateConnections="true" doc:name="Gmail"/>
<flow name="attemptsendemailFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/sendemail" doc:name="HTTP"/>
<set-payload value="Hello" doc:name="Set Payload"/>
<smtp:outbound-endpoint host="smtp.gmail.com" user="myemail#gmail.com" password="mypwd" connector-ref="Gmail" to="myemail#gmail.com" from="myemail#gmail.com" subject="This is a test." responseTimeout="10000" doc:name="SMTP"/>
</flow>
</mule>
When I open the browser and type localhost:8081/sendemail, no email is sent and the browser prints this message.
Failed to route event via endpoint: DefaultOutboundEndpoint{endpointUri=smtp://myemail%40gmail.com:<password>#smtp.gmail.com, connector=GmailSmtpConnector
{
name=Gmail
lifecycle=start
this=17e9bc9e
numberOfConcurrentTransactedReceivers=4
createMultipleTransactedReceivers=true
connected=true
supportedProtocols=[smtp]
serviceOverrides=<none>
}
, name='endpoint.smtp.myemail.gmail.com', mep=ONE_WAY, properties={fromAddress=myemail#gmail.com, toAddresses=myemail#gmail.com, subject=This is a test.}, transactionConfig=Transaction{factory=null, action=INDIFFERENT, timeout=0}, deleteUnacceptedMessages=false, initialState=started, responseTimeout=10000, endpointEncoding=UTF-8, disableTransportTransformer=false}.
Funny thing is, I tested the exact same xml in other computers and it works.
I would first test if your computer has connectivity to the Gmail servers.
Try "telnet smtp.gmail.com 587" or the Mac equivalent.
I can't see the port "587" in your flow.You can try the following configuration:
<smtp:outbound-endpoint
connector-ref="emailConnector"
host="smtp.gmail.com"
port="587"
user="<account name>%40gmail.com"
password="<password>"
to="<email addresses>"
from="<account name>#gmail.com"
subject="Test email message"/>
Also check if you have access to call the smtp.gmail.com from your local network
In the Scatter-gater I have an error on the route2, it says
*******************************************************************************
Message : Exception was found for route(s): 2. Message payload is of type: Prediccion
Code : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. Exception was found for route(s): 2. Message payload is of type: Prediccion (org.mule.routing.CompositeRoutingException)
org.mule.routing.CollectAllAggregationStrategy:51 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/routing/CompositeRoutingException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
org.mule.routing.CompositeRoutingException: Exception was found for route(s): 2. Message payload is of type: Prediccion
at org.mule.routing.CollectAllAggregationStrategy.aggregateWithFailedRoutes(CollectAllAggregationStrategy.java:51)
at org.mule.routing.CollectAllAggregationStrategy.aggregate(CollectAllAggregationStrategy.java:38)
at org.mule.routing.ScatterGatherRouter.processResponses(ScatterGatherRouter.java:210)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
Prediccion is the class that returns the auto transformer connected at the other side of the scatter-gater, I've used a lot of transformers but it doesn't work with any of them
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:twitter="http://www.mulesoft.org/schema/mule/twitter" xmlns:db="http://www.mulesoft.org/schema/mule/db" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:smtp="http://www.mulesoft.org/schema/mule/smtp"
xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.6.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/smtp http://www.mulesoft.org/schema/mule/smtp/current/mule-smtp.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.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
http://www.mulesoft.org/schema/mule/db http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd
http://www.mulesoft.org/schema/mule/twitter http://www.mulesoft.org/schema/mule/twitter/current/mule-twitter.xsd">
<smtp:gmail-connector name="gmail" doc:name="Gmail"/>
<http:request-config name="HTTP_Request_Configuration" host="api.openweathermap.org" port="80" basePath="data/2.5/forecast/daily?q=San Fernando,es&lang=es&units=metric&cnt=1&mode=json" doc:name="HTTP Request Configuration"/>
<spring:beans>
<spring:bean id="transformador" name="Bean" class="com.trabajosd.Transformador"/>
</spring:beans>
<db:mysql-config name="MySQL_Configuration" host="${db.host}" port="${db.port}" user="${db.user}" password="${db.password}" database="${db.database}" doc:name="MySQL Configuration"/>
<twitter:config name="Twitter__Configuration" accessKey="3006010565-rUz6h4xnNoHO2juxGYQEK5jcM5DvSpxv7P3hv07" accessSecret="KxcqDQEo6JbHHR2S10lFN5luxXLEJauNhiBdZIeY7tUXO" consumerKey="LBxBQUYhbAFb5PeBtR7Jg4Evo" consumerSecret="AdD8lJYRS1OadJsn2BXhEbnhdcUNc1t3uM9pnOGH7eNfE2JxZu" doc:name="Twitter: Configuration"/>
<flow name="trabajosdFlow">
<poll doc:name="Poll">
<fixed-frequency-scheduler frequency="10000"/>
<http:request config-ref="HTTP_Request_Configuration" path="/" method="GET" doc:name="HTTP"/>
</poll>
<logger level="INFO" doc:name="Logger"/>
<json:json-to-object-transformer doc:name="JSON to Object"/>
<auto-transformer returnClass="com.trabajosd.Prediccion" name="JsonDataToPrediccion"></auto-transformer>
<scatter-gather doc:name="Scatter-Gather">
<processor-chain>
<custom-filter class="com.trabajosd.Filtro" doc:name="Custom"/>
<set-payload value="Predicción de lluvia para hoy en #[payload.getCiudad()]" doc:name="Set Payload"/>
<smtp:outbound-endpoint host="${mail.host}" port="${mail.port}" user="${mail.user}" password="${mail.password}" connector-ref="gmail" to="${mail.to}" from="MULE" subject="Prediccion Meteorológica" responseTimeout="10000" doc:name="Send notification email"/>
</processor-chain>
<db:insert config-ref="MySQL_Configuration" doc:name="Database">
<db:dynamic-query><![CDATA[insert into valores(tiempo,pais,ciudad,humedad,presion,velocidad_viento) values ('#[payload.getTiempo()]','#[payload.getPais()]','#[payload.getCiudad()]','#[payload.getHumedad()]','#[payload.getPresion()]', '#[payload.getVelocidad_viento()]')]]></db:dynamic-query>
</db:insert>
<twitter:update-status config-ref="Twitter__Configuration" status="#[payload.toString()]" doc:name="Twitter"/>
</scatter-gather>
<catch-exception-strategy doc:name="Catch Exception Strategy">
<logger level="INFO" doc:name="Logger"/>
</catch-exception-strategy>
</flow>
<catch-exception-strategy name="trabajosdCatch_Exception_Strategy">
</catch-exception-strategy>
</mule>
I have a Spring MVC Web application that performs CRUD operations on Tomcat Server. Can I use Mule ESB as a request handler before Tomcat. For example, users request to localhost:8181/user/create (Mule ESB Port) and Mule redirect request to localhost:8080/user/create (Tomcat Server Port) and sends response back over mule. I am using Mule ESB for webservices, but I don't understand how can I use Mule ESB for web application requests.
You can use the new HTTP module released in 3.6 and create a proxy using this flow:
<?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"
xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
<http:listener-config name="proxyConfig" host="localhost" port="${proxyPort}" />
<http:request-config name="requestConfig" host="localhost" port="${httpPort}" />
<flow name="proxyTemplate">
<http:listener config-ref="proxyConfig" path="/*" responseStreamingMode="AUTO" parseRequest="false" >
<http:response-builder statusCode="#[message.inboundProperties['http.status']]" reasonPhrase="#[message.inboundProperties['http.reason']]" />
</http:listener>
<copy-properties propertyName="*" />
<remove-property propertyName="http.*" />
<copy-attachments attachmentName="*" />
<set-property propertyName="X-Forwarded-For" value="#[message.inboundProperties['http.remote.address']]" />
<http:request config-ref="requestConfig" method="#[message.inboundProperties['http.method']]" path="#[message.inboundProperties['http.request.path']]" parseResponse="false" >
<http:request-builder>
<http:query-params expression="#[message.inboundProperties['http.query.params']]" />
</http:request-builder>
</http:request>
<copy-properties propertyName="*" />
<remove-property propertyName="http.*" />
<copy-attachments attachmentName="*" />
</flow>
</mule>
How am i supposed to disable the amqp-gen queues that creates automatically? in Mule ActiveMQ i got a "disableTemporaryReplyToDestinations" property, by setting that to 'true' and doing a one-way exchange-pattern, i'm able to implement async messaging.
Now with AMQP/RabbitMQ it's a different story, i do have the one-way exchange pattern but i dont have any property to set from the component side inside MuleStudio that tells me to disable those, i can't even disable it from the RabbitMQ Panel.
How do i disable those tempQueues (called amqp-gen in AMQP) which are not needed for an async implementation?
This is my test XML
<mule xmlns:amqp="http://www.mulesoft.org/schema/mule/amqp" xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" version="CE-3.3.1" 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/amqp http://www.mulesoft.org/schema/mule/amqp/current/mule-amqp.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 ">
<amqp:connector name="AMQP_Connector" validateConnections="true"
host="arbuzqorks"
port="1111"
fallbackAddresses="localhost:5672"
doc:name="AMQP Connector"/>
<flow name="rabbitmq_demoFlow1" doc:name="rabbitmq_demoFlow1">
<http:inbound-endpoint exchange-pattern="one-way" host="localhost" port="8081" path="rabbitmq" doc:name="HTTP"/>
<set-payload value="#['This is a test message that...']" doc:name="Setting payload"/>
<amqp:outbound-endpoint exchangeType="direct" responseTimeout="10000" doc:name="AMQP" connector-ref="AMQP_Connector" exchangeName="async-direct-test" exchangeDurable="true" queueDurable="true"/>
</flow>
<flow name="async-rabbitmqFlow1" doc:name="async-rabbitmqFlow1">
<amqp:inbound-endpoint exchange-pattern="one-way" exchangeName="async-direct-test" exchangeDurable="true" queueDurable="true" responseTimeout="10000" connector-ref="AMQP_Connector" doc:name="AMQP"/>
<byte-array-to-string-transformer doc:name="Byte Array to String"/>
<set-payload value="#[payload + ' passed into the consumer flow']" doc:name="adding string to payload"/>
<amqp:outbound-endpoint exchange-pattern="one-way" routingKey="test_response" exchangeType="direct" exchangeDurable="true" queueDurable="true" responseTimeout="10000" connector-ref="AMQP_Connector" doc:name="AMQP" exchangeName="async-direct-test"/>
</flow>
<flow name="async-rabbitmqFlow2" doc:name="async-rabbitmqFlow2">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" path="asyncamqp" doc:name="HTTP"/>
<component class="com.web.esb.component.AsyncMessageRequestorComponent" doc:name="Request AMQP Message"/>
</flow>
</mule>
Your "issue" is not related to temporary queues and trying to disable them but in fact is a feature called "private queues" (see the doc for more information).
Basically, because you do not name the queues you declare in your AMQP inbound and outbound endpoints, RabbitMQ consider them as private to your connection and give them generated names.
Use the queueName attribute to configure queue names on your AMQP endpoints and things will work as you intend.