如何使用Mule模式访问postgreSQL数据库?

时间:2013-10-08 21:58:28

标签: postgresql jdbc mule

我能记录一些消息,但如何更改它以访问数据库并发送这些消息并存储在那里?

我知道数据库部分已从模式中删除但尝试了一些事情,到目前为止没有任何工作。

代码:

<scripting:transformer name="noopLoggingTransformer">
    <scripting:script engine="groovy">
        log.info "insert into inbound_messages (payload, timestamp, agent, ip_from, endpoint, soap_operation) values ('',now(), ${message.getInboundProperty('user-agent')}, ${message.getInboundProperty('MULE_REMOTE_CLIENT_ADDRESS')}, ${message.getInboundProperty('http.request')}, '');"
        message
    </scripting:script>
</scripting:transformer>

<pattern:web-service-proxy name="service" transformer-refs="noopLoggingTransformer" inboundAddress="${serverName}/services/Logradouros/LogradouroServico" outboundAddress="${targetServer}/servicos/v2/LogradouroServico.svc" wsdlFile="LogradouroServicos.wsdl">
</pattern:web-service-proxy>

<jdbc-ee:postgresql-data-source name="dbconection" user="${database.user}" password="${database.pass}" url="${database.url}" transactionIsolation="UNSPECIFIED" doc:name="PostgreSQL Data Source">
</jdbc-ee:postgresql-data-source>

<jdbc-ee:connector name="jdbcConnector" dataSource-ref="dbconection" validateConnections="false" transactionPerMessage="true" queryTimeout="10" pollingFrequency="10000" doc:name="JDBC"> 
    <jdbc-ee:query key="querymsg" value="insert into inbound_messages (payload, timestamp, agent, ip_from, endpoint, soap_operation) values ('', now(), '','','')"></jdbc-ee:query>  
</jdbc-ee:connector>

我之后尝试了不同的方法:

<flow name="logradouros-autenticacao" doc:name="logradouros-autenticacao"> 
    <servlet:inbound-endpoint path="${webservice.logradouros.in.autenticacao.path}" responseTimeout="10000" doc:name="HTTP"></servlet:inbound-endpoint>  
    <async doc:name="Async"> 
        <flow-ref name="log-request" doc:name="Flow Reference"></flow-ref>  
    </async>  
    <outbound-endpoint exchange-pattern="request-response" address="${webservice.logradouros.out.protocol}://${webservice.logradouros.out.host}/${webservice.logradouros.out.autenticacao.path}" doc:name="Generic"></outbound-endpoint>  
</flow>

<flow name="log-request" doc:name="log-request"> 
    <logger message="1-&gt; #[groovy:payload.getClass()]" level="INFO" doc:name="Logger"></logger>  
    <jdbc-ee:outbound-endpoint exchange-pattern="one-way" queryKey="insertMsg" responseTimeout="10000" queryTimeout="-1" connector-ref="jdbcConnector" doc:name="Persist raw message"></jdbc-ee:outbound-endpoint>  
    <logger message="#[header:INBOUND:Host] #[header:INBOUND:http.method] #[message.inboundProperties.entrySet().toString()] #[groovy:payload.toString()] #[groovy: return message.getInboundPropertyNames().toString()] #[groovy: return message.getInboundProperty('request.parameters').toString()]" level="INFO" category="mule.http.accesslog" doc:name="Logger"></logger>  
    <logger message="#[message.outboundProperties.entrySet().toString()]" level="INFO" category="mule.http.accesslog" doc:name="Logger"></logger>  
</flow>

它不是100%但它可以锻炼,通过模式的方法不起作用......

1 个答案:

答案 0 :(得分:1)

在变换器中,使用muleContext.client将消息分派给另一个流消耗的VM队列,这将处理数据库中的插入数据。

因此,在您的情况下,类似于以下内容应该有效:

<scripting:transformer name="noopLoggingTransformer">
    <scripting:script engine="groovy">
        muleContext.client.dispatch('vm://log-request.in', message)
        message
    </scripting:script>
</scripting:transformer>

<pattern:web-service-proxy name="service" transformer-refs="noopLoggingTransformer" inboundAddress="${serverName}/services/Logradouros/LogradouroServico" outboundAddress="${targetServer}/servicos/v2/LogradouroServico.svc" wsdlFile="LogradouroServicos.wsdl" />

<flow name="log-request" doc:name="log-request"> 
    <vm:inbound-endpoint path="log-request.in" />
    <logger message="1-&gt; #[groovy:payload.getClass()]" level="INFO" doc:name="Logger" />
    <jdbc-ee:outbound-endpoint exchange-pattern="one-way" queryKey="insertMsg" responseTimeout="10000" queryTimeout="-1" connector-ref="jdbcConnector" doc:name="Persist raw message" />
    <!-- TODO use MEL, not these old style expressions -->
    <logger message="#[header:INBOUND:Host] #[header:INBOUND:http.method] #[message.inboundProperties.entrySet().toString()] #[groovy:payload.toString()] #[groovy: return message.getInboundPropertyNames().toString()] #[groovy: return message.getInboundProperty('request.parameters').toString()]" level="INFO" category="mule.http.accesslog" doc:name="Logger" />  
    <logger message="#[message.outboundProperties.entrySet().toString()]" level="INFO" category="mule.http.accesslog" doc:name="Logger" />
</flow>