WSO2 task to run exactly once at startup - wso2

I need a task to be run exactly once at the wso2 startup. How do we ensure this.
The following did not work in the scheduled task
<trigger once="true"/>

Try with
<trigger count="1" interval="1"/>

I am using the ESB 4.8.1. For me both configurations are worked fine. Followings are the sample schedule tasks which I have tested in each case.
1.Configuration 1 -<trigger once="true"/>
<?xml version="1.0" encoding="UTF-8"?>
<task xmlns="http://ws.apache.org/ns/synapse" name="MyTask" class="org.apache.synapse.startup.tasks.MessageInjector" group="synapse.simple.quartz">
<trigger once="true"/>
<property xmlns:task="http://www.wso2.org/products/wso2commons/tasks" name="message">
<name xmlns="">The message will be displayed once</name>
</property>
</task>
2.Configuration -<trigger count="1" interval="1"/>
<?xml version="1.0" encoding="UTF-8"?>
<task xmlns="http://ws.apache.org/ns/synapse" name="MyTask" class="org.apache.synapse.startup.tasks.MessageInjector" group="synapse.simple.quartz">
<trigger count="1" interval="1"/>
<property xmlns:task="http://www.wso2.org/products/wso2commons/tasks" name="message">
<name xmlns="">The message will be displayed once</name>
</property>
</task>
However, in the ESB documentation recommended to use <trigger once="true"/> to execute tasks only once after the esb starts.

I also had the same problem (using ESB4.9). After trying lots of options I found a working config to be:
<trigger once="true" count="1" interval="1"/>

There seems to be a bug that is still present in the latest ESB (Integrator v. 6.4.0).
The only way a trigger will launch on startup and/or deployment of CAR archive, is if you set the interval to any number higher than 1000. I set it to 1001 and it ran straight away both on deployment as well as on restart. Example config below:
<?xml version="1.0" encoding="UTF-8"?>
<task class="org.apache.synapse.startup.tasks.MessageInjector" group="synapse.simple.quartz" name="TSK_Logoff" xmlns="http://ws.apache.org/ns/synapse">
<trigger interval="1001" count="1" />
<property name="sequenceName" value="SEQ_Logoff" xmlns:task="http://www.wso2.org/products/wso2commons/tasks"/>
<property name="injectTo" value="sequence" xmlns:task="http://www.wso2.org/products/wso2commons/tasks"/>
<property name="message" xmlns:task="http://www.wso2.org/products/wso2commons/tasks">
<logoff/>
</property>

Just for the record, the version that I was using was 4.8.1. I did not solve this issue, instead worked-around it and moved the feature that we had to do an exactly once. I moved that from the WSO2 startup to our web layer and thus saved ourselves the trouble of fighting with various WSO2 version upgrades in the future.
I know that this issue happened in early 2016 and it looks odd for me to answer it in March 2019. But this issue seems to be happening on the newer version of WSO2 as well and fellow architects have been referring/commenting to this post even in Jan 2019. Therefore, it would be appropriate for me to comment on what I finally did.

Related

ERROR {InvokeMediator} - {api:EmailMicroService} Sequence named Value {name ='null', keyValue ='techlogixSmtp'} cannot be found

Scenario
I'm using Wso2 Email Connector for sending emails to our company's smtp server. Following is the code for connection and Api
Connection
<?xml version="1.0" encoding="UTF-8"?>
<localEntry key="techlogixSmtp" xmlns="http://ws.apache.org/ns/synapse">
<email.init>
<connectionType>SMTPS</connectionType>
<password>xxxx</password>
<host>smtp.techlogix.com</host>
<requireTLS>true</requireTLS>
<port>25</port>
<name>techlogixSmtp</name>
<username>xxxx</username>
</email.init>
</localEntry>
Api
<?xml version="1.0" encoding="UTF-8"?>
<api context="/email" name="EmailMicroService" port="8290" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST" uri-template="/send">
<inSequence>
<log level="full"/>
<email.send configKey="techlogixSmtp">
<from>{json-eval($.from)}</from>
<to>{json-eval($.to)}</to>
<subject>{json-eval($.subject)}</subject>
<content>{json-eval($.content)}</content>
<contentType>{json-eval($.contentType)}</contentType>
<attachments>{json-eval($.attachments)}</attachments>
</email.send>
<respond/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
</api>
Question
I'm facing the ERROR {InvokeMediator} - {api:EmailMicroService} Sequence named Value {name ='null', keyValue ='techlogixSmtp'} cannot be found. What possible configuration is missing from my end which is causing this issue?
I made sure that updated Api is deployed on MicroIntegrator
As Sanoj, mentioned your Local Entry techlogixSmtp seems not deployed to the Runtime. So in your CompositeExporter Project make sure your techlogixSmtp is checked and the correct Server Role is selected. Please refer to the following image.

How to increase the server startup timeout in WSO2 Integration Studio?

I want to make an oracle database connection by opening a dataservice project with WSO2 Integration studio application. I can connect to the Oracle database. But when I run the dataservice project, the WSO2 Integration Studio application goes into time out and asks us to increase the time out time. How and where should we increase this time?
Integration Studio Dataservice project Xml :
<data transports="http https" serviceGroup="" serviceNamespace="" name="demoDataService">
<description />
<resource method="GET" path="GetGenders">
<call-query href="GetGenders" />
</resource>
<config id="OracleDataSourceIdenfierName" enableOData="true">
<property name="driverClassName">oracle.jdbc.driver.OracleDriver</property>
<property name="url">jdbc:oracle:thin:#host:port/schema_name</property>
<property name="username">username</property>
<property name="password">password</property>
</config>
<query id="GetGenders" useConfig="OracleDataSourceIdenfierName">
<sql>SELECT column1,column2 FROM schema_name.table_name</sql>
<result outputType="json">{
"Genders": {
"Gender": [
{
"column1": "$column1",
"column2": "$column2"
}
]
}
}</result>
<properties>
<property name="fetchDirection">forward</property>
</properties>
</query>
</data>
WSO2 Integration Studio Timeout Error:
Go to Window -> Show View -> Other Then search for Servers. Select Servers and click on Open.
Then Double Click on the "Micro Integrator Server 4.1" Then look for the timeout settings.

JMS transaction roll back in WSO2 ESB4.9.0

I've created a JMS listener as below. Everything is working fine as the listener is able to receive the messages from Q. But when my end point is down due to some reasons the message is not roll backing to Q. Would like to know the jms transaction boundary & will I be able to roll back transactoion if my end point fails. Currently it's not happening, anything I am missing here
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="TestJMSListener"
transports="jmslistener1,jmslistener2"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<call>
<endpoint key="StoreJMSMSg"/>
</call>
</inSequence>
<faultSequence>
<property name="SET_ROLLBACK_ONLY" value="true" scope="axis2"/>
</faultSequence>
</target>
<parameter name="transport.jms.ContentType">application/xml</parameter>
<parameter name="transport.jms.Destination">TestQueue</parameter>
<description/>
</proxy>
Have you also set the following in axis2.xml?
<parameter name="transport.jms.SessionTransacted">true</parameter>
The Guaranteed Delivery EIP ensures safe delivery of a message by storing it locally and transmitting it to the receiver's data store. Even when the receiver is offline, the EIP ensures that the message goes through when the receiver comes online.
Using message stores and message processors you can overcome this. Please refer the link.

How to call sequence in Task Scheduler in wso2 esb

I want to run a proxy(pass through) or a sequence(pass through type) repeatatively after every 60 seconds so i started with Task Scheduler but i am not able to figure out how can i achieve my requirement using Task Scheduler. I want to execute my proxy or sequence after every 60 seconds.Like in wso2 BPS we can achieve this thing using loops, Likewise is there anything in esb that can schedule run a proxy or sequence after certain interval of time? Looking forward to your answers.
Thanks in advance.
IS it possible to achieve above requirement in wso2 esb. Please Help.
You can use the task to run a proxy service which is configured in your ESB. You need to configure the task as below.
Here is a sample configuration to access the SimpleStockQuoteService sample service which comes with the ESB. You can replace the value of the "to" property to match your proxy endpoint and set the desired message.
<task class="org.apache.synapse.startup.tasks.MessageInjector" name="CheckPrice">
<property name="to" value="http://localhost:9000/services/SimpleStockQuoteService"/>
<property name="soapAction" value="urn:getQuote"/>
<property name="message">
<m0:getQuote xmlns:m0="http://services.samples">
<m0:request>
<m0:symbol>IBM</m0:symbol>
</m0:request>
</m0:getQuote>
</property>
<trigger interval="5"/>
</task>
Form WSO2 ESB version 4.7.0 new properties are added to task component. Using those we can call a proxy service or sequence from our task scheduler. Below are my sample code for calling a proxy service
<task name="DBPOller"
class="org.apache.synapse.startup.tasks.MessageInjector"
group="synapse.simple.quartz">
<trigger count="2" interval="5"/>
<property xmlns:task="http://www.wso2.org/products/wso2commons/tasks"
name="soapAction"
value="urn:getRequestForm"/>
<property xmlns:task="http://www.wso2.org/products/wso2commons/tasks" name="message">
<p:getRequestForm xmlns:p="http://ws.wso2.org/dataservice"><!--Exactly 1 occurrence--><p:isRead>n</p:isRead>
</p:getRequestForm>
</property>
<property xmlns:task="http://www.wso2.org/products/wso2commons/tasks"
name="injectTo"
value="proxy"/>
<property xmlns:task="http://www.wso2.org/products/wso2commons/tasks"
name="proxyName"
value="DBPollerService"/>
</task>

WSO2 ESB: WARNING: EPRs are NULL. Transport configuration my be incorrect

When activating a proxy (with the Web UI), I always get following error message:
WARNING: EPRs are NULL. Transport configuration may be incorrect
But I just don't understand why and what it means?
The source of the proxy:
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse" name="patient_toMPI_pJMS_qPatientToMPI" statistics="disable" trace="disable" transports="jms">
<parameter name="transport.jms.Destination">patient_qPatientToMPI</parameter>
<parameter name="transport.jms.ConnectionFactory">queueNonBlocking</parameter>
<parameter name="transport.jms.DestinationType">queue</parameter>
<parameter name="transport.jms.ContentType">
<rules>
<jmsProperty>contentType</jmsProperty>
<default>application/xml</default>
</rules>
</parameter>
<target faultSequence="errorSequence">
<inSequence>
<log level="custom">
<property name="Patient/toMPI" value="proxy (patient_toMPI_pJMS_qPatientToMPI) called"/>
</log>
<sequence key="patient_toMPI_sTransform"/>
</inSequence>
</target>
</proxy>
Simple fix :) Simply go to "Edit Data Service" and tick http and https on "Transport Settings"
This has already been reported as a bug here. It will be resolved in future releases.
Are you logged in as the super tenant? If so you should not be getting this issue. Aforementioned bug, we experienced only in tenant-mode.
Please make sure, you have copied required (correct) client libraries into repository/components/lib directory in ESB to allow connection between the ESB and the JMS provider.
For eg: If the provider is active-mq, you need to copy following jar files.
activemq-core-xxx.jar AND geronimo-j2ee-management_xx_spec-xx.jar