向frontline 连接器发送一个通用消息,并具有可定制的属性。这些都是用'DefaultInspectionRequestHandler.class'属性处理的。
identifier:send_commit_message
属性
类型。要转换的事件类型,在Frontline 连接器中。
可能的值。字符串
connection_timeout。超时时间,以秒为单位
可能的值:Numeric_value
save_response。保存响应的上下文
可能的值:步骤,工作流程
构成要素
标识符。用于集成服务的ID(例如,任务ID)。
属性。参数的集合,可由集成服务使用。
属性在内部被转换为一个地图,其值可以是一个递归转换的集合。最终的地图以JSON字符串的形式存储在消息的payload String 中,原始值如字符串、数字和布尔值被存储在属性Map-field内。这使得消息在与集成服务进行通信时非常灵活。
响应处理
发送提交信息时,有三种可能的结果。
当在指定时间后没有收到响应时,就会发生超时。这种情况发生的原因是信息在网络中丢失,或者服务器需要太多的时间来处理结果。
在这种情况下,错误通常意味着意外的行为,如由于网络错误或服务器错误导致的信息发送失败。
预期的错误处理(如处理过程中的无效状态等)是通过一个成功的响应完成的。
所有的响应都会产生一个具有 "send_commit_message"模式的输入事件。该命令是RESPONSE_OK、RESPONSE_TIMEOUT 和RESPONSE_ERROR中的一个。
消息包含一个有效载荷对象,其中包含响应的额外数据。
在出错和超时的情况下,有效载荷包含的字段 "类型"和 "标识符"被设置为请求中使用的相同值。如果需要,这可以用来识别特定请求的错误。
在成功的情况下,这些字段是不存在的,但是字段 "status"被设置为一个数值(由集成服务中的处理程序定义)。这个值可用于处理流程中预期的错误情况。
在所有情况下,字段响应包含一个由集成服务定义的字符串,可用于进一步区分响应。
除了状态和响应值之外,集成服务还可以定义额外的属性,以便与事件一起发送回来。这些属性在事件处理时作为上下文变量可用。这方面的一个例子是,从客户的WMS发回一个错误信息,用于错误处理或处理成功提交的额外信息(见下文的片段)。
实例
<send_commit_message id="pre_task_request" type="PRE_TASK_REQUEST" connection_timeout="600">
<properties>
<param name="group" type="string">#{group}</param>
<param name="aisle" type="string">#{aisle}</param>
</properties>
</send_commit_message>
<send_commit_message id="complete_inspection" type="COMPLETE_INSPECTION" connection_timeout="1500">
<param name="identifier">#{cockpit_id}</param>
</send_commit_message>
标识符的值不能有效地设置为标签属性--这在创造者的未来迭代中应该是可以实现的。
<send_commit_message id="send_asset_info" type="PHOTO" connection_timeout="60">
<properties>
<param name="asset_uri" type="string">#{event:payload.media_file}</param>
<param name="order_id" type="string">?{pickOrder.name}?</param>
<param name="group_id" type="string">?{pickOrder.groups[activeGroup].label}?</param>
<param name="customer_reference">?{pickOrder.groups[activeGroup].picks[0].article.customerReference}?</param>
<param name="amount" type="string">?{pickOrder.groups[activeGroup].picks[0].amountOpen}?</param>
</properties>
</send_commit_message>
上传图像资产,并发送一个带有上传资产信息的承诺信息。
这个例子的步骤只是期待一个图像资产URI(media_file)作为输入。
<step id="send_asset" uitemplate="WAIT" persist="false" screen_lock_enabled="false" debug_mode="false">
<actions>
<action id="upload_media" type="trigger_upload_asset">
<param name="asset_uri">#{media_file}</param>
<param name="delete_after_upload" type="bool">true</param>
<param name="upload_immediately" type="bool">true</param>
<param name="upload_immediately_delete_on_failure" type="bool">true</param>
</action>
<send_commit_message id="send_asset_info" type="PHOTO" connection_timeout="200">
<properties>
<param name="asset_uri" type="string">#{event:payload.asset_uri}</param>
<param name="asset_name" type="string">#{event:payload.asset_name}</param>
<param name="asset_version" type="string">#{event:payload.asset_version}</param>
</properties>
</send_commit_message>
<ui_notification id="show_nok" type="WARN">
<duration>SHORT</duration>
<message>Picture NOT OK</message>
</ui_notification>
<ui_notification id="show_upload_error" type="ERROR">
<duration>SHORT</duration>
<message>Media upload failed</message>
</ui_notification>
<ui_notification id="show_commit_error" type="ERROR">
<duration>SHORT</duration>
<message>Commit failed</message>
</ui_notification>
</actions>
<states>
<onresume>
<rule id="auto_exec">
<expression>1</expression>
<actions>
<action ref="upload_media"/>
</actions>
</rule>
</onresume>
<onevent>
<rule id="upload_ok">
<expression>
<![CDATA[#{event(trigger_upload_asset):command} == 'OK']]>
</expression>
<actions>
<action ref="send_asset_info"/>
</actions>
</rule>
<rule id="upload_error">
<expression>
<![CDATA[#{event(trigger_upload_asset):command} == 'ERROR' || #{event(trigger_upload_asset):command} == 'NETWORK_ERROR' || #{event(trigger_upload_asset):command} == 'INTERNAL_ERROR']]>
</expression>
<actions>
<action ref="show_upload_error"/>
<action ref="finish"/>
</actions>
</rule>
<rule id="commit_ok_ok">
<expression>
<![CDATA[#{event(send_commit_message):command} == 'RESPONSE_OK' && #{event(send_commit_message):payload.response} == 'OK']]>
</expression>
<actions>
<action ref="finish_workflow"/>
</actions>
</rule>
<rule id="commit_ok_nok">
<expression>
<![CDATA[#{event(send_commit_message):command} == 'RESPONSE_OK' && #{event(send_commit_message):payload.response} != 'OK']]>
</expression>
<actions>
<action ref="show_nok"/>
<action ref="goto_take_picture"/>
</actions>
</rule>
<rule id="commit_error_or_timeout">
<expression>
<![CDATA[#{event(send_commit_message):command} == 'RESPONSE_ERROR' || #{event(send_commit_message):command} == 'RESPONSE_TIMEOUT']]>
</expression>
<actions>
<action ref="show_commit_error"/>
<action ref="goto_take_picture"/>
</actions>
</rule>
</onevent>
</states>
</step>
用自定义错误状态处理
<actions>
<!-- dialog references variables set by the commit message response for error handling -->
<ui_dialog id="sap_error" type="Error" title="Error">
<message><![CDATA[#{sap_message}<br>Continue to '#{sap_material}/#{sap_position}'?]]></message>
<buttons>
<button>
<text>ANDRRES_fw</text>
<command>SAP_FIX</command>
<focused>true</focused>
</button>
<button>
<text>ANDRRES_bw</text>
<command>DO_NOT_TRY_AGAIN</command>
</button>
</buttons>
</ui_dialog>
<!-- more actions
[...]
-->
</actions>
<!-- more WF code
[...]
-->
<onevent>
<!-- Technical success but check for SAP response -->
<rule id="success">
<expression><![CDATA[#{event:command} == 'RESPONSE_OK' && #{event:payload.status} == 0 ]]></expression>
<actions>
<ui_notification id="show_done" type="INFO">
<duration>SHORT</duration>
<message>#{cockpit_id} completed...</message>
</ui_notification>
<action ref="close_ds_task"/>
<action ref="finish_workflow"/>
</actions>
</rule>
<rule id="sap_error_in_success">
<expression><![CDATA[#{event:command} == 'RESPONSE_OK' && #{event:payload.status} == 500 ]]></expression>
<actions>
<!-- variables are automatically set when the event is handled and can be used in the action -->
<action ref="sap_error"/>
</actions>
</rule>
<rule id="unknown_error_in_success">
<expression><![CDATA[#{event:command} == 'RESPONSE_OK' && #{event:payload.status} != 0 && #{event:payload.status} != 500 ]]></expression>
<actions>
<action ref="completion_error"/>
</actions>
</rule>
<rule id="request_error">
<expression><![CDATA[#{event:command} == 'RESPONSE_ERROR']]></expression>
<actions>
<action ref="completion_error"/>
</actions>
</rule>
<rule id="request_timeout">
<expression><![CDATA[#{event:command} == 'RESPONSE_TIMEOUT']]></expression>
<actions>
<action ref="completion_error"/>
</actions>
</rule>
</onevent>
MQTT实例
<send_commit_message id="send_mqtt" type="FRONTLINE_MQTT" connection_timeout="200">
<properties>
<param name="mqtt" type="string"><![CDATA[?{
var mqtt = {
topic: "MY/TOPIC",
content: "MY CONTENT"
};
var stringmqtt = JSON.stringify(mqtt);
stringmqtt;}?]]>
</param>
</properties>
</send_commit_message>
处理者一方
下面是一个在连接器中处理代码的例子,在'检查'请求处理程序内。
@Override
public CommitMessageResponse handleCommitMessage(CommitMessage aCommit) {
if("COMPLETE_INSPECTION".equals(aCommit.getType())) {
String evaluation = aCommit.getIdentifier();
// HANDLE EVENT
// [CODE]
if(isSuccess) {
log.info("Completion success!");
return new CommitMessageResponse(aCommit, 0, "Success!");
}
// HANDLE ERROR
CommitMessageResponse cmr = new CommitMessageResponse(aCommit, 500, "SAP Error!");
cmr.addProperties("sap_message", cr.getMessage()); // 'cr' is an object specific to the custom code
cmr.addProperties("sap_material", cr.getMaterial());
cmr.addProperties("sap_position", cr.getPosition());
return cmr;
}
// OTHER MESSAGES
在错误案例中添加的属性将在事件被处理时对工作流可用。