简体   繁体   English

Biztalk XLANG transform() output Biztalk 编排内部循环中的相同随机值

[英]Biztalk XLANG transform() output the same random value in a loop inside Biztalk orchestration

I wrote a map to generate an HL7 message header (MSH).我写了一个 map 来生成一个 HL7 消息 header (MSH)。 For the MSH.10 segment, by definition should be unique so I put the following in my map.对于 MSH.10 段,根据定义应该是唯一的,所以我将以下内容放在我的 map 中。

    public string MessageControlId()
    {
       //return System.DateTime.Now.ToString("yyyyMMddHHmmssffff");


       string firstPart = System.DateTime.Now.ToString("yyyyMMdd");
       string middlePart = new Random().Next( 1000, 9999 ).ToString();
       string lastPart = System.DateTime.Now.ToString("ffff");
        
       return firstPart + middlePart + lastPart;
    }

在此处输入图像描述

Then in my orchestration I call the header map multiple time in a loop.然后在我的编排中,我在一个循环中多次调用 header map。 My goal is to generate multiple HL7 messages, each with its own message header and a unique MSH.10 value.我的目标是生成多个 HL7 消息,每个消息都有自己的消息 header 和唯一的 MSH.10 值。

在此处输入图像描述

The code below is based on Microsoft Biztalk XLANG syntax which invokes the map to transform and create the message header via the transform() statement.下面的代码基于Microsoft Biztalk XLANG语法,它调用 map 以通过 transform() 语句转换和创建消息 header。

tMapType = System.Type.GetType(msgBre.HeaderMapName);

transform (msgHeader) = tMapType(msgBilling);

However, when I tested this out I see multiple HL7 message generated but many of them have duplicate value in term of their MSH.10 segment.但是,当我对此进行测试时,我看到生成了多个 HL7 消息,但其中许多消息在其 MSH.10 段方面具有重复值。 I grouped them in different color below.我在下面将它们分组为不同的颜色。

在此处输入图像描述

I expect separate value each time because in my code I generate a random number between 1000 and 9999. Plus I also generate the time value to the thousand of a second.我希望每次都有单独的值,因为在我的代码中,我生成了一个介于 1000 和 9999 之间的随机数。另外,我还生成了千分之一秒的时间值。

Do you know why this occur?你知道为什么会这样吗? My only theory is when I call the tranform() function, it does not really invoke the map to recreate the header each time...that seems wrong to me.我唯一的理论是当我调用 tranform() function 时,它并没有真正调用 map 来重新创建 header 每次......这对我来说似乎是错误的。

You are using Random object which is a pseudo-random number generator, so it returns the same sequence of numbers with a same seed.您正在使用 Random object 这是一个伪随机数生成器,因此它返回具有相同种子的相同数字序列。 You are not giving a seed explicitly to the constructor, so it uses default seed which is based on a system clock.您没有明确地向构造函数提供种子,因此它使用基于系统时钟的默认种子。 If you are creating Random objects in a tight loop with a default seed then next() function will return you the same number multiple times, which I think is what happens here.如果您使用默认种子在紧密循环中创建 Random 对象,那么 next() function 将多次返回相同的数字,我认为这就是这里发生的情况。

You should either give unique seed explicitly or use the same Random object all the time (if it is possible).您应该明确给出唯一的种子或始终使用相同的随机 object(如果可能的话)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM