Shuttle ESB (i)--Getting Started instance

Source: Internet
Author: User
Tags readline msmq visual studio
Download Shuttle ESB

From the GitHub Project release page, download the latest release version.
SHUTTLE-ESB Source Package list :http://www.nuget.org/packages?q=shuttle-esb
Publish page
:https://github.com/Shuttle/shutle-esb/releases


using MSMQ QuickStart

Because the shuttle ESB requires a queue to operate, we use Microsoft's MSMQ to implement it. Before you make an instance, you must make sure that MSMQ is installed on your computer.
Installing MSMQ:http://msdn.microsoft.com/en-us/library/aa967729%28v=vs.110%29.aspx


Let's create a very simple instance. We send a command to the host server that the server receives and displays.


Note: Make sure that all projects (source code and your new project) are under the same version of the framework (as in the Framework 4.0) to ensure that services of the Ihost type are functioning properly.


vs Solutions

Build a VS solution and create a new empty scenario.
First click to create a new project;
Select the Visual Studio solution in other project types and click Blank Solution template;
To the solution named: Quickstart.shuttle;

Click OK to complete the creation.


message

Because our message is shared, create a separate component sharing control. Create a new project named: QuickStart.Shuttle.Messages.

Create a new class named Writebluemessagecommand, and write the following code:

Namespace QuickStart.Shuttle.Messages
{public
    class Writebluemessagecommand
    {public
        string bluemessage {get; set;}}}


Client

Create a new console application, named: QuickStart.Shuttle.Client, and add a reference:
QuickStart.Shuttle.Messages (Project Reference)
SHUTTLE-ESB-MSMQ (source code can be downloaded)

Add the following code to the console application implementation:

Using System;
Using QuickStart.Shuttle.Messages;
Using Shuttle.Core.Infrastructure;
Using Shuttle.ESB.Core;
Namespace QuickStart.Shuttle.Client
{
    internal class program
    {
        private static void Main (string[] args )
        {
            var bus = servicebus.create (). Start (); 
Coloredconsole.writeline (
                Consolecolor.darkgray,
                "(To exit press ENTER on a empty line):");
            Coloredconsole.writeline (
                consolecolor.darkgray, 
                "Enter a message to write with blue on the server and press Enter :");
            Console.WriteLine ();
var message = Console.ReadLine ();
while (!string. IsNullOrEmpty (message))
            {
                bus. Send (New Writebluemessagecommand
                            {
                                bluemessage = message
                            });
message = Console.ReadLine ();
            }
Bus. Dispose ();}}}


The Shuttle ESB needs to know where the messages go. Since we are using the default message routing vendor, we need the path defined in the application configuration file. Add a path to the project configuration:

<?xml version= "1.0"?>
<configuration>
    <configSections>
        <section name= " Servicebus "Type=" Shuttle.ESB.Core.ServiceBusSection, Shuttle.ESB.Core "/>
    </configSections>
<serviceBus>
        <messageRoutes>
            <messageroute uri= "Msmq://./quickstart_server_inbox_work" >
                <add specification= "StartsWith" value= "QuickStart"/>
            </messageRoute>
        </ messageroutes>
    </serviceBus>
</configuration>


Its role is to tell the shuttle ESB to send all the messages. The starting point is QuickStart, the end is Msmq://./quickstartserverinbox_work


Service Side

Create a new project QuickStart.Shuttle.Server and add the following references:
QuickStart.Shuttle.Messages (Project Reference)
SHUTTLE-ESB-MSMQ (source code file)

Create a new class named Servicebushost, because we will use a common hosting server, so we need a common main entry point. It implements the Ihost interface to find the classes that need to be executed. So our Servicebushost class needs to implement the Ihost interface.

Using System;
Using Shuttle.Core.Host;
Using Shuttle.ESB.Core;
Namespace QuickStart.Shuttle.Server
{public
    class Servicebushost:ihost, IDisposable
    {
        private static Iservicebus bus;
public void Start ()
        {
            bus = servicebus.create (). Start (); 
        }
public void Dispose ()
        {
            bus. Dispose ();}}}


Our service bus instance, which needs to process an input queue, is configured in the configuration file:

<?xml version= "1.0"?>
<configuration>
    <configSections>
        <section name= " Servicebus "Type=" Shuttle.ESB.Core.ServiceBusSection, Shuttle.ESB.Core "/>
    </configSections>
<serviceBus>
        <inbox
            workqueueuri= "msmq://./quickstart_server_inbox_work"
            errorqueueuri= " Msmq://./quickstart_server_inbox_error "/>
    </serviceBus>
</configuration>


For the terminal to be able to start efficiently, we need to do some configuration. Build the local referenced assembly copy of your server project. Open the project properties, then click the Debug tab, and in the Startup type, select Start external program. Then select Shuttle.Core.Host.exe in the bin directory of this project as the startup project (because of the reference, so it will appear here.) Seems to be nonsense ~ ~)
For the message acceptance mechanism of the shuttle ESB, we create a handler (Handler) for each message type. Let's create a handler for the Writebluemessagecommand message. Create a new class named Writebluemessagehandler, and inherit the Imessagehandler interface.

Using System;
Using QuickStart.Shuttle.Messages;
Using Shuttle.Core.Infrastructure;
Using Shuttle.ESB.Core;
Namespace QuickStart.Shuttle.Server
{public
    class writebluemessagehandler:imessagehandler< writebluemessagecommand>
    {public
        void ProcessMessage (handlercontext<writebluemessagecommand> Context)
        {
            Coloredconsole.writeline (consolecolor.blue, context. message.bluemessage);
        }
public bool IsReusable
        {
            get {return true;}
        }
    }


Running the solution

To be able to run the solution properly, you need to do the following: Right-click the solution, select the Startup Project tab, and then select the Multi-boot project, then select Client and server.

Then, you can run and test it.

You have created a very simple instance based on an ESB, but this example is relatively rudimentary. From here you can learn about the samples and engage with the community to expand your reach.


example Download :http://download.csdn.net/detail/liu765023051/7754559

Original address :http://shuttle.github.io/shuttle-esb/getting-started/index.html


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.