How to do a databse polling in wso2 mediator? - wso2

I would like to make a database polling in wso2 mediator, but it seems there is no mediator ready to do that.
My problem is that I have tried to make a listener task with a dblookup but I have combined more than 10 mediators and it seems that it is not the best way.
What I need to do is: listen to a field in the databse, when the field is changed, I will fire an external webservice.
Should I create a custom mediator for polling or are there ready mediators?
wso2 docs are not enough to complete my scenario.

I guess you'll need your 10 mediators. My approach would be like this
1.) store the actual value of the field in a database (e.g. internal H2 database) using dbreport mediator (https://docs.wso2.com/display/ESB481/DB+Report+Mediator)
2.) create a scheduled task that triggers your proxy
3.) create a proxy that retrieves the value from the database where you stored the last value, use dblookup mediator (https://docs.wso2.com/display/ESB481/DBLookup+Mediator) to retrieve the actual value from your database. If the values are different do something using filter mediator and update the value in your local db (https://docs.wso2.com/display/ESB481/Filter+Mediator)
My approach depends on how fast the value in the db changes. If there's a high frequency I assume this will not work properly.

Have you tried using DB listener inbound with WSO2 ESB? This solves your problem.
[1] https://store.wso2.com/store/assets/esbconnector/details/da8c396a-281e-493b-87bc-b55a4cebe92d
Best Regards,
Malaka

Related

Loopback default values for missing properties when fetching data from MongoDB

How should I define the Loopback model so that all the properties listed in the model JSON file would always appear on the result even when those properties have no value (or are missing) from the MongoDB record? Should this behaviour be configured in the Loopback or in the MongoDB?
Thanks!
MongoDB is a Schema-less database. It is designed in this way to give us flexibility for adding new fields to a document without any need to restart the database. So I don't think that it is a good idea to handle this scenario on the database side.
I think the best way to handle this could be setting a default value for every property in LoopBack model definition. This solution has a problem when some data is inserted into the database from outside the project.
You can also handle missing parameter at the front-end side.
Another solution that I can think of, is implementing an afterRemote method for checking the existence of all the fields. In this case, you can use this function after any API route that you want to. You can check the following link for more information:
https://loopback.io/doc/en/lb3/Remote-hooks.html#signature

wso2 cep stored procedures in SQL Server 2016

I am trying to run a stored procedure in WSO2 CEP with SQL Server 2016. Is this possible? I already looked through the documentation on this which is scarce. there is only one sample with connection to SQL Server.
Although, it looks like it is limited to selects, inserts and deletes.
I was not able to find any documentation on other driver functionality through CEP.
Also, I did find some information on other WSO2 Services, not wso2 CEP, which might allow me to run the stored procedures. If you have any information on that and who to plug CEP with those services It would help as well.
WSO2CEP is a real time analytics product which provides few SQL operations with RDBMS publisher to publish events as mentioned in the documentation [1].
Only work around would be modifying existing query defined output-event-adapters.xml file located in <CEP-Location>/repository/conf direcory. Inside the file locate <adapterConfig type="rdbms"> element and you will find properties of SQL operations such as update into like below.
<property key="updateTableRow">UPDATE $TABLE_NAME SET $COLUMN_VALUES WHERE $CONDITION</property>
You can change above like below to execute stored procedure
<property key="updateTableRow">EXEC $TABLE_NAME $COLUMN_VALUES</property>
Then in RDBMS publisher you need to change execution.mode as update.
[1] https://docs.wso2.com/display/CEP400/RDBMS+Event+Publisher

Stored Procedure Returning Multiple Result Sets Not Working in WSO2 DSS

I am using WS02 Data Services Server (version 3.2.2) to genearte an oputput from a stored procedure which returns 2 results sets.
result set 1: the actual records returned from the query.
result set 2: the total number of records returned.
I would like to aggregate both result sets into one XML output. I tried to use 'Output Mapping' options, but it is still not working.
Any help (inclusing documentation etc.) would be greatly appreciated.
Thanks.
At the moment, WSO2 Data Services Server doesn't support multiple ref cursors or nested ref cursors. There is a Jira[1] for this improvement.
[1] https://wso2.org/jira/browse/DS-544
You can try this tutorial Writing a Data Service to execute a stored procedure with WSO2 DSS

DB Polling in WSO2 ESB or PS

I am writing some business flow using WSO2 Process Server. I want to start a process when there is any new entry in a specific table. i.e. we do DB Polling in oracle process.
So whenever there is a new entry in table, i need to fetch those data and start processing on those data using BPEL.
The above explained scenario can be achieved using task component of WSO2 ESB. Using task component we can schedule the call to a proxy service after certain interval and we can use that proxy to fetch the data from database.

Insertion with two or more tables from Wso2 ESB with DSS

I have one query:-
In my ESB 4.7.0, Dss is 3.0.1
I wish to insert the data reliably into database,for that i am getting one array list from client.
That array i need to insert into 3 different tables.Each table gave to me returned generated key.which will help to insert into
2nd table,same process for 3rd table.
for this i am using 3 different insertion operations in wso2esb using wso2dss,the insertion is happening nicely ..
#my issue is while i am inserting into 2nd or 3rd table the error has been occurred due to network issue or any data related issue.
In that case my transaction could be roll back.i have done in transaction mediator but it's helpful for within the sequence .
it's not reflecting to any other sequence , so how could i do this.for this may i use any class mediator or any new thing.
The transaction mediator is designed to cater the atomicity requirement. Since you are using insertion only without the involvement of deletion you can pass the primary key of inserted entry in the first table to a class mediator and delete but i think, in this case atomicity will not be guranteed. Therefore the concept of transaction is not achieved in this case.
Since you are using three different opperations you can use DSS boxcarring feature along with Query Request Export feature which enables you to do transactions in a coordinated way. Please refer this to see how you can use boxcarring feature. It allows individual queries executed in a boxcarring session to communicate with each other. The concept is 'exporting' a specific result element so that the next calling query will get that result element as a query parameter. So, if you've two queries, namely, 'query1' and 'query2' that's executed sequentially in a boxcarring session, and if 'query1' has a specific result element and that element is exported with the name 'foo', then 'query2' also gets a query param named 'foo'. So when this boxcarring session is executed, the query1's exported value will be passed into query2 as an input parameter.
For your requirement the ideal solution is to use Boxcarring. Boxcarring is a method of grouping a set of service calls together and executing them at once. Where applicable, a boxcarring session works in a transactional manner such as when used with an RDBMS data source.
The 'Data Service Hosting' feature facilitates boxcarring by grouping service calls in the server side. As a result, special service clients are not required and as usual, successive service calls can be made to the server to participate in a boxcarring session.
For boxcarring to function, a transport that supports session management, such as HTTP, must be used. The service client should also support session management by returning back session cookies when sent by the server. Axis2 Service Clients have full support for session management.
Please find the WSO2 original documentation on boxcarring and this useful blog post that explain how to work with boxcarring step by step.