Implement LAN message push using shuttle ESB

Source: Internet
Author: User
Tags msmq connectionstrings mule esb

The full name of ESB is Enterprise Service Bus. It is a product of the combination of traditional middleware technologies and XML, web services, and other technologies.

The emergence of ESB has changed the traditional software architecture and can provide cheaper solutions than traditional middleware Products. At the same time, it can eliminate technical differences between different applications, it allows different application servers to coordinate operations and realize communication and integration between different services.

See, the function of ESB is so powerful. Mule ESB is commonly used in Java, and to. net, shuttle ESB is gradually accepted by people as a new ESB. The following example describes how to create and push a shuttle ESB.

1. we need to introduce the shuttle ESB-related class library-shuttle. core. data, shuttle. core. domain, shuttle. core. host, shuttle. core. infranstructure, shuttle. ESB. core, shuttle. ESB. MSMQ, shuttle. ESB. to ensure consistent version, we can install the nuget plug-in vs to download the class library required by shuttle ESB;

2. add the shuttle ESB configuration file app to pub. config and shuttle ESB read the database content through the configuration file to obtain the sub-end working queue Uri and the type of messages that the sub-end can accept. The configuration content is as follows:

<?xml version="1.0"?><configuration><configSections><section name="serviceBus" type="Shuttle.ESB.Core.ServiceBusSection, Shuttle.ESB.Core"/><section name="sqlServer" type="Shuttle.ESB.SqlServer.SqlServerSection, Shuttle.ESB.SqlServer"/></configSections><appSettings><add key="SubscriptionManagerSecured" value="false"/></appSettings>  <connectionStrings>    <clear/>    <add name="SubscriptionConnection" connectionString="Uid=sa;Pwd=123456;Initial Catalog=shuttle;Data Source=172.22.51.180;Connect Timeout=900" providerName="System.Data.SqlClient"/>  </connectionStrings><sqlServer subscriptionManagerConnectionStringName="SubscriptionConnection"/><serviceBus>    <inbox      workQueueUri="msmq://./pubsub-publish-inbox-work"      deferredQueueUri="msmq://./pubsub-publish-inbox-deferred"      errorQueueUri="msmq://./shuttle-pubsub-error"/></serviceBus><startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
3. Start a bus on pub to push data:

            //连接数据库            new ConnectionStringService().Approve();            //配置信息            subscriptionManager = SubscriptionManager.Default();            //创建 消息通道            bus = ServiceBus                .Create(c => c.SubscriptionManager(subscriptionManager))                .Start();            Console.WriteLine();            ColoredConsole.WriteLine(ConsoleColor.Green, "Server bus started.  Press CTRL+C to stop.");
After creating a bus, use the bus. Publish method to push messages to sub;

4. Add the shuttle ESB configuration file app. config on the sub end. The shuttle ESB writes the message type that can be received by the current sub end and the URI of the current Working queue to the database through the configuration file. The pub end determines whether to send certain types of data to a sub end based on the Message Type written to the database by sub end and the work queue URI. The configuration file of the sub end is as follows:

<?xml version="1.0"?><configuration>  <configSections>    <section name="serviceBus" type="Shuttle.ESB.Core.ServiceBusSection, Shuttle.ESB.Core"/>  </configSections>  <connectionStrings>    <clear/>    <add name="Subscription" connectionString="Uid=sa;Pwd=123456;Initial Catalog=shuttle;Data Source=172.22.51.180;Connect Timeout=900" providerName="System.Data.SqlClient"/>  </connectionStrings>  <serviceBus>    <inbox       workQueueUri="msmq://./pubsub-subscriber1-inbox-work"       errorQueueUri="msmq://./shuttle-pubsub-error"/>  </serviceBus><startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
5. Start a bus on the sub end to receive data pushed by the pub end;

            //连接数据库            new ConnectionStringService().Approve();            //配置信息            subscriptionManager = SubscriptionManager.Default();            /*              * 配置接收消息的类型:              *   风报警解除、雨报警解除、雪报警解除、异物报警解除、地震报警解除              *                 * 远程实验三个实体              */            subscriptionManager.Subscribe(                new[] {                     typeof(WindInfoAlarmEntity).FullName,                     typeof(RainInfoAlarmEntity).FullName,                     typeof(SnowInfoAlarmEntity).FullName,                    typeof(FreignMatterAlarmEntity).FullName,                    typeof(EarthquakeAlarmEntity).FullName,                    typeof(String).FullName                }            );            //创建 消息通道            bus = ServiceBus                     .Create(c => c.SubscriptionManager(subscriptionManager))                     .Start();            Console.WriteLine();            ColoredConsole.WriteLine(ConsoleColor.Green, "Server bus started.  Press CTRL+C to stop.");
The description in the bus shows the data types that can be processed by the current sub, such as the windinfoalarmentity and string types.

6. Create a corresponding handler on the sub end and receive different types of data push through generic restrictions. Handler for processing string types is as follows:

using System;using System.Collections.Generic;using System.Linq;using System.Text;using Shuttle.ESB.Core;using Shuttle.Core.Infrastructure;using ICT.MainFramework.ViewEntity;using ICT.RCS.Server.ESB;namespace PublishSubscribe.Subscriber1{    public class WindRainSnowStrHandler : IMessageHandler<String>    {        public void ProcessMessage(HandlerContext<String> context)        {            string strType = context.Message.Split('#')[0].ToString();            //ESB接收处理消息            MessageTransfer.transferDataToEntity(MainServerForm.bus, context.Message);        }        public bool IsReusable        {            get { return true; }        }    }}
To solve offline data push, shuttle ESB uses MSMQ as the message queue and caches the messages to be processed to MSMQ.
After the pub and sub ends of the shuttle ESB are created, the running effect is that after pub publishes a message through the bus, the LAN has already registered the message in the work queue URI of the database, the sub-end that meets the corresponding message type can receive messages published by the pub end, and the observer mode is used perfectly.

The principle of shuttle ESB is clear, and mule ESB and JBoss ESB can be understood at a glance.

I hope my explanation will help you further understand shuttle ESB.

Implement LAN message push using shuttle ESB

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.