Pesquisar

Este conteúdo não está disponível no idioma selecionado.

3.3. .NET AMQP 1.0 Client API

download PDF
.NET AMQP 1.0 Client API is based on the GitHub Azure Amqp.Net Lite Client API, see .
Note
This is an initial version of documentation for the .NET client. Regular updates and enhancements of the documentation can be expected after the GA release of Fuse 6.2.0

3.3.1. Getting Started with .NET AMQP 1.0 Client API

3.3.1.1. Introduction to .NET AMQP 1.0 Client API

What is AMQPNet.Lite?
The Advanced Message Queuing Protocol Net Lite is a lightweight AMQP 1.0 client library for .Net Framework 3.5 and 4.0 to support desktop clients. For detailed
Note
At present, Red Hat does not provide the libraries for Micro Framework, Compact Framework, Windows Phone, Windows RT, nor Windows Store.
Hardware and Software Requirements to setup AMQPNet.Lite SDK
  • Visual Studio version 2012 or 2013
  • .NET Framework support for Common Language Runtime (CLR) versions 2.0 and 4.
  • Windows Desktop machine
Installing the SDK
Unzip the amqpnetlite-sdk-1.1.0.2.zip file in a directory on a windows machine.
Contents of the AMQPNet.Lite SDK
  • The pre-compiled binary (.dll) files and the associated debug program database (.pdb) files.
  • Source files of examples which demonstrate using this SDK and AMQP.
  • Amqpnetlite API documentation,see InstallDir\doc\html\index.html
AMQPNet.Lite Examples
The following examples are available in the SDK
  • HelloWorld-simple Minimal send-receive through brokered topic.
  • HelloWorld-robust Send-receive with more features.
  • Interop.Drain, Interop.Spout-Interoperate with Apache Qpid using simple send and receive.
  • Interop.Client, Interop.Server - Interoperate with Apache Qpid C++ Messaging using request and response.
  • PeertoPeer - Client and Server programs illustrate using the Amqpnetlite library to create peer-to-peer connections without using an intermediate broker system.
  • Receive Selector - Receive messages matching filter criteria
  • Anonymous Relay - Like Interop.Client but detects and uses peer ANONYMOUS-RELAY capability for sending all messages over a single link, regardless of destination address.
Note
For detailed information on the examples, see the README.txt file at in your installed SDK directory at, InstallDir/amqpnetlite/Examples.

3.3.1.2. A Simple Messaging Program in AMQPNet.Lite

This section demonstrates the HelloWorld_simple example, it is a simple example that creates a Sender and a Receiver for the same address, sends a message to the address, reads a message from the address, and prints the result
By default, this example connects to a broker running on localhost:5672.
Building the Example
The extracted SDK contains two files, InstallDiramqpnetlite/amqp.sln and InstallDiramqpnetlite/amqp-vs2012.sln. The amqp.sln is the project file for Visual Studio 2013 solution and the amqp-vs2012.sln is the project file for Visual Studio 2012 solution.
To build the examples, follow these steps:
  • Go to the directory where you extracted the SDK, open amqp.sln solution file with Visual Studio 2013
  • In the Solution Explorer window, you can view all the examples.
  • To build the examples, click BUILD icon.
  • The Output window shows the build status.
Running the Example
To run the example, ensure that A-MQ Broker is running on the system. See Section 3.2.2, “Configuring the Broker for AMQP” for details on setting up an A-MQ broker.
To run the HelloWorld_simple example using the DOS prompt follow these steps:
  • On the terminal, navigate to the directory where SDK is installed, i.e InstallDir/amqpnetlite/bin/Debug
  • On the command prompt enter the Helloworld-simple.exe
    By default, this program connects to a broker running on localhost:5672. You can specify a host and port, and the AMQP endpoint address explicitly on the command line:, for example HelloWorld_simple amqp://localhost:5672 amq.topic
    By default, this program addresses its messages to amq.topic. In Amqp brokers amq.topic is a predefined endpoint address and is immediately available with no broker configuration.
  • On Success, you can see the output on the DOS prompt as: HelloWorld!
To run the HelloWorld_simple example using Visual Studio 2013 follow these steps:
  • In Visual Studio 2013 Solution Explorer window, right-click on Helloworld-simple example.
  • Select Set as Startup Project option from the panel.
  • In Solution Explorer window, click on HelloWorld-simple.cs file and open the source code
    using System;
    using Amqp;
    
    namespace HelloWorld_simple
    {
        class HelloWorld_simple
        {
            static void Main(string[] args)
            {
                string broker  = args.Length >= 1 ? args[0] : "amqp://localhost:5672";
                string address = args.Length >= 2 ? args[1] : "amq.topic";
    
                Address brokerAddr = new Address(broker);
                Connection connection = new Connection(brokerAddr);
                Session session = new Session(connection);
    
                SenderLink sender = new SenderLink(session, "helloworld-sender", address);
                ReceiverLink receiver = new ReceiverLink(session, "helloworld-receiver", address);
    
                Message helloOut = new Message("Hello World!");
                sender.Send(helloOut);
    
                Message helloIn = receiver.Receive();
    
                Console.WriteLine(helloIn.Body.ToString());
    
                connection.Close();
            }
        }
    }
    
  • Insert a breakpoint at the last line in the source file at connection.Close();,and click Start
  • On success, you can see the output on the console window as Hello World!
Red Hat logoGithubRedditYoutubeTwitter

Aprender

Experimente, compre e venda

Comunidades

Sobre a documentação da Red Hat

Ajudamos os usuários da Red Hat a inovar e atingir seus objetivos com nossos produtos e serviços com conteúdo em que podem confiar.

Tornando o open source mais inclusivo

A Red Hat está comprometida em substituir a linguagem problemática em nosso código, documentação e propriedades da web. Para mais detalhes veja oBlog da Red Hat.

Sobre a Red Hat

Fornecemos soluções robustas que facilitam o trabalho das empresas em plataformas e ambientes, desde o data center principal até a borda da rede.

© 2024 Red Hat, Inc.