Mule ESB数据库插入仅在Mule重启后才能工作

时间:2015-08-12 15:21:04

标签: mysql database oracle mule

我正在尝试使用for-each插入MySQL,因为我的输入JSON可以有多个值。

employee idprojectnamestartdate是强制性的,每次都会将它们插入数据库。

虽然可能有其他字段,但只有在重新启动Mule后才会将它们插入到数据库中。此代码在重新启动Mule(插入所有值)后突然再次停止工作(仅插入强制值),然后在重新启动后再次工作。

我启用了日志记录,我可以看到JSON输入格式正确。

以下是我的Mule配置xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:db="http://www.mulesoft.org/schema/mule/db" 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.5.0"
    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/json http://www.mulesoft.org/schema/mule/json/current/mule-json.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/db http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd
http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd">
    <flow name="addprojectdetailsFlow1" doc:name="addprojectdetailsFlow1">
        <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8085" doc:name="HTTP" path="addProjectDetails"/>
        <json:json-to-object-transformer returnClass="java.util.HashMap" doc:name="JSON to Object"/>
        <!--  logger message="#[message:payload]" level="INFO" doc:name="Logger"/-->
        <foreach collection="#[payload.newprojects.projects]" doc:name="For Each">
            <db:insert config-ref="testMysqlLocal" doc:name="Database">
                <db:parameterized-query><![CDATA[INSERT INTO Project (employee_id, projectname, notes, StartDate, EndDate, ClientRate, EmployeeRate) VALUES (#[payload.employeeid],#[payload.projectname],#[payload.notes],#[payload.StartDate],#[payload.EndDate],#[payload.ClientRate],#[payload.EmployeeRate]);]]></db:parameterized-query>
            </db:insert>
        </foreach>
        <response>
            <http:response-builder doc:name="HTTP Response Builder">
                <http:header name="Access-Control-Allow-Origin" value="*"/>
                <http:header name="Content-Type" value="application/json;charset=UTF-8"/>
            </http:response-builder>
        </response>
        <response>
            <json:xml-to-json-transformer doc:name="XML to JSON"/>
        </response>
        <response>
            <mulexml:xslt-transformer maxIdleTransformers="2" maxActiveTransformers="5" xsl-file="/AnypointStudio/workspace/databasetest/validateaddProjectDetailsResponse.xsl" doc:name="XSLT"/>
        </response>
        <mulexml:object-to-xml-transformer doc:name="Object to XML"/>
    </flow>
</mule>

Here is my Json sample.

{
    "newprojects": {
        "projects": [
            {
                "employeeid": "2",
                "projectname": "1112",
                "notes": "projectanotes",
                "StartDate": "2015-01-01",
                "EndDate": "2015-01-01",
                "ClientRate": "20",
                "EmployeeRate": "20"
            },
            {
                "employeeid": "2",
                "projectname": "1121",
                "notes": "projectanotes",
                "StartDate": "2015-01-01",
                "EndDate": "2015-01-01",
                "ClientRate": "20",
                "EmployeeRate": "20"
            }
        ]
    }
}

有没有人遇到过同样的问题,或者看到有什么不妥之处?

0 个答案:

没有答案