官术网_书友最值得收藏!

Versioning messages

Even though I can honestly say that I have developed interfaces that could accommodate any change made to both sides without ever modifying the interface, most people don't design to that extreme. There will, more likely than not, come a time where you will have to change a message to accommodate a new feature or request, and so on. Now, we get into the issue of message versioning.

To enable support for versioned messages, we need to ensure the required components are configured. The simplest way to achieve this is as follows:

var bus = RabbitHutch.CreateBus( "host=localhost", services =>   services.EnableMessageVersioning() )

Once support for versioned messages is enabled, we must explicitly opt-in any messages we want to be treated as versioned. So as an example, let's say we have a message defined called MyMessage. As you can see in the following message, it is not versioned and all versions will be treated the same way as any other when it is published:

public class MyMessage
{
public string Text { get; set; }
}

The next message that you see will be versioned, and ultimately it will find its way to both the V2 and previous subscribers by using the ISupersede interface:

public class MyMessageV2 : MyMessage, ISupersede<MyMessage>
{
public int Number { get; set; }
}
主站蜘蛛池模板: 洮南市| 重庆市| 揭东县| 湘潭市| 莱阳市| 师宗县| 辽源市| 托里县| 浠水县| 沭阳县| 七台河市| 沛县| 鄂托克前旗| 门源| 奉化市| 全椒县| 彰化县| 碌曲县| 句容市| 大洼县| 江达县| 叙永县| 长顺县| 连平县| 醴陵市| 湘阴县| 望江县| 西乌珠穆沁旗| 重庆市| 秭归县| 广丰县| 额尔古纳市| 奉化市| 西宁市| 安丘市| 西城区| 梧州市| 高碑店市| 武隆县| 乌兰察布市| 祁连县|