在Octopus中,如何在NServiceBus实例-mapping.xml上进行变量替换
在C项目中使用NServiceBus时,将使用名为instance-mapping.xml的文件指定每个队列驻留在哪台机器上。像这样:在Octopus中,如何在NServiceBus实例-mapping.xml上进行变量替换,nservicebus,octopus-deploy,Nservicebus,Octopus Deploy,在C项目中使用NServiceBus时,将使用名为instance-mapping.xml的文件指定每个队列驻留在哪台机器上。像这样: <?xml version="1.0" encoding="utf-8" ?> <endpoints> <endpoint name="QueueName1"> <instance machine="localhost"/> </endpoint> <en
<?xml version="1.0" encoding="utf-8" ?>
<endpoints>
<endpoint name="QueueName1">
<instance machine="localhost"/>
</endpoint>
<endpoint name="QueueName2">
<instance machine="localhost"/>
</endpoint>
</endpoints>
<?xml version="1.0" encoding="utf-8" ?>
<endpoints>
<endpoint name="QueueName1">
<instance machine="server1"/>
</endpoint>
<endpoint name="QueueName2">
<instance machine="server2"/>
</endpoint>
</endpoints>
在Octopus中,如何对这样的文件进行变量替换?因此,QueueName1内的机器属性更改为server1,QueueName2内的机器属性更改为server2。像这样:
<?xml version="1.0" encoding="utf-8" ?>
<endpoints>
<endpoint name="QueueName1">
<instance machine="localhost"/>
</endpoint>
<endpoint name="QueueName2">
<instance machine="localhost"/>
</endpoint>
</endpoints>
<?xml version="1.0" encoding="utf-8" ?>
<endpoints>
<endpoint name="QueueName1">
<instance machine="server1"/>
</endpoint>
<endpoint name="QueueName2">
<instance machine="server2"/>
</endpoint>
</endpoints>
Octopus具有内置功能,可以在appsettings和ConnectionString上进行简单的键/值替换。但是上面的文件有点复杂,因为封闭的元素标识了密钥。我可能过于简化了您的问题,但为了得到所需的instance-mapping.xml,我将使用配置转换。示例instance-mappings.transform.xml文件如下:
<?xml version="1.0" encoding="utf-8" ?>
<endpoints xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<endpoint name="QueueName1" xdt:Locator="Match(name)">
<instance machine="server1" xdt:Transform="SetAttributes" />
</endpoint>
<endpoint name="QueueName2" xdt:Locator="Match(name)">
<instance machine="server2" xdt:Transform="SetAttributes" />
</endpoint>
</endpoints>
如果在开发过程中添加本地端点存在摩擦,而这些摩擦在其他环境中没有意义,那么可以使用八达通作为端点的真实来源。要实现这一点,请将每个端点的变量添加到八达通项目中:
然后,可以根据Octopus中的值在转换文件中设置端点:
<?xml version="1.0" encoding="utf-8" ?>
<endpoints xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform" xdt:Transform="Replace">
#{each e in endpoint}
<endpoint name="#{e.Name}">
<instance machine="#{e.Machine}"/>
</endpoint>
#{/each}
</endpoints>
我希望这有帮助。有趣的方法。我将用它做实验。这是可行的,因为八达通首先进行转换,变量替换第二次?解决方案2很有魅力。非常感谢你!