I need to modify a large amount of material information in MES, in order to avoid a material modification failure to cause the whole DEE rollback, I plan to modify the material information code packaged into multiple Integration execution, but I do not know how to use DEE to create Integration
How to create a MES to MES Integration Entries using DEE, please give an example code, thanks a lot!
Hi Joy,
In order to create a new integration entry via DEE, you can follow the sample code below. This sample creates a new integration entry from “MES to MES” using the Message Type “CreateIntegrationEntrySample”. The JSON payload consists of an array of objects representing dummy material data.
// Foundation
UseReference("Cmf.Foundation.BusinessObjects.dll", "Cmf.Foundation.BusinessObjects.Abstractions");
// System
UseReference("%MicrosoftNetPath%\\System.Text.Json.dll", "System.Text.Json");
UseReference("", "System.Text");
#region Service Provider
IServiceProvider _serviceProvider = (IServiceProvider)Input["ServiceProvider"];
IEntityFactory _entityFactory = _serviceProvider.GetService<IEntityFactory>();
#endregion Service Provider
// Demo payload: a Materials array with a couple of sample entries
var payload = new
{
Materials = new[]
{
new { MaterialId = "MAT-0001", Name = "Sample Material 1", PrimaryQuantity = 10.0 },
new { MaterialId = "MAT-0002", Name = "Sample Material 2", PrimaryQuantity = 25.5 }
}
};
string message = System.Text.Json.JsonSerializer.Serialize(payload);
var newIntegrationEntry = _entityFactory.Create<IIntegrationEntry>();
newIntegrationEntry.Name = Guid.NewGuid().ToString();
newIntegrationEntry.SourceSystem = "MES";
newIntegrationEntry.TargetSystem = "MES";
newIntegrationEntry.MessageType = "CreateIntegrationEntrySample";
newIntegrationEntry.EventName = "CreateIntegrationEntrySample";
newIntegrationEntry.SystemState = IntegrationEntrySystemState.Received;
var integrationMessage = _entityFactory.Create<IIntegrationMessage>();
integrationMessage.Message = Encoding.UTF8.GetBytes(message);
newIntegrationEntry.IntegrationMessage = integrationMessage;
newIntegrationEntry.Create();
Please ensure the message type is added to the MessageType lookup table.
To process this entry you can create another DEE. That DEE does not need any action group and receives the context Integration Entry through its input dictionary:
IIntegrationEntry integrationEntry = Input["IntegrationEntry"] as IIntegrationEntry;
Finally, to connect all the dots, you need to update the IntegrationHandlerResolution smart table, with the respective integration entry metadata (source, target and message type). Enter the GenericIntegrationHandler as the handler type and add the name of the DEE that will process the message on Action Name.