This topic describes how to prepare the environment for accessing Message Queue for Apache RocketMQ by using the TCP client SDK for .NET so that you can use the SDK for .NET to send and receive messages.

Before you use the SDK for .NET, take note of the following points:
  • An application that uses Message Queue for Apache RocketMQ must be deployed on Alibaba Cloud Elastic Compute Service (ECS).
  • Go to the console to create the topics and group IDs that are referred to in the code. Message tags can be specified by application users. For more information about how to create a message tag, see Create resources.

Windows SDK for .NET overview

The SDK for .NET provided by Alibaba Cloud is a managed wrapper for the Message Queue for Apache RocketMQ SDK for C++. This ensures that the SDK for .NET is completely independent of the public library of the Windows SDK for .NET. C++ multi-thread concurrent processing is used to ensure the efficiency and stability of the SDK for .NET.

When Visual Studio is used to develop .NET applications and class libraries, the default target platform is AnyCPU. This means that the x86 or x64 platform can be automatically selected based on the CPU type. During running, the Just-in-Time (JIT) compiler in the common language runtime (CLR) of .NET converts the IL code into the x86 or x64 machine code. The DLL generated by the C or C++ compiler is the machine code. Therefore, a target platform is selected during compilation. When the compilation options are set, the C or C++ project is compiled as an x64 64-bit DLL. Therefore, the 64-bit DLL in release mode compiled using Visual Studio 2015 and .NET Framework 4.5.2 is provided. The 64-bit DLL in release mode is also available to other Visual Studio versions.

Important
  • The SDK for .NET supports only the Windows 64-bit operating system.
  • C++ DLL files require the installation package of the Visual C++ 2015 runtime environment. If the Visual Studio 2015 runtime environment is not installed, run the vc_redist.x64.exe program provided in the SDK.

Download the Windows SDK for .NET

We recommend that both new users and existing users that are not concerned with upgrade costs download the latest version of the SDK for .NET. For information about the download URL for the latest version of the SDK for .NET, see Release notes.

Download and decompress the package. The following directory structure is displayed:
  • lib/
    Contains files related to the underlying C++ DLL and the installation package of the Visual C++ 2015 runtime environment. If the Visual Studio 2015 runtime environment is not installed, copy the following code to install the vc_redist.x64.exe program. The actual SDK file may vary based on the SDK version that you downloaded.
      64/
          ONSClient4CPP.lib
          ONSClient4CPP.dll
          ONSClient4CPP.pdb
        vc_redist.x64.exe                    
  • demo/

    Contains sample code for sending normal messages, one-way messages, and ordered messages. This directory also includes sample code for the consumption of normal messages and ordered messages.

  • interface/

    Encapsulates PInvoke code. The code must be included in your project code.

  • SDK_GUIDE.pdf

    Contains the documentation and frequently asked questions (FAQ) about how to prepare the SDK environment.

  • changelog

    Contains bug fixes and new features in the new releases.

Configuration for using the SDK for .NET in Visual Studio 2015

  1. Use Visual Studio 2015 to create your project. createproject
  2. Right-click the project and choose Add > Add Existing Item to add all files in the interface directory of the downloaded SDK package. interface
  3. Right-click the project and choose Properties > Configuration Manager. Set Active solution configuration to Release and set Active solution platform to x64.
  4. Write and compile the test program, save the DLL file of the SDK to the directory of the executable file or to the system directory, and then run the program. ddl
    Note

    The SDK provides a preconfigured demo project. You can directly open the project and compile it. When you run the project, copy the following related DLL file to the directory of the executable file:

    copyddl

Configuration for using the Message Queue for Apache RocketMQ SDK in Visual Studio 2015 ASP.NET

  1. Create a Web Forms project for ASP.NET by using Visual Studio 2015. Web Forms
  2. Right-click the project and choose Properties > Configuration Manager. Set Active solution configuration to Release and set Active solution platform to x64. x64
  3. Right-click the project and choose Add > Add Existing Item to add all files in the interface directory of the downloaded SDK package.

    For more information about how to configure a common .NET project, see Step 2.

  4. Add the code for starting and stopping the SDK to the Global.asax.cs file.
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Optimization;
    using System.Web.Routing;
    using System.Web.Security;
    using System.Web.SessionState;
    using ons;    // The namespace where the SDK is located. 
    using test;   // The namespace where the classes of a wrapper SDK are located. 
    namespace WebApplication4
    {
      public class Global : HttpApplication
      {
           void Application_Start(object sender, EventArgs e)
           {
               // Code that runs on application startup
               RouteConfig.RegisterRoutes(RouteTable.Routes);
               BundleConfig.RegisterBundles(BundleTable.Bundles);
               try
               {
                   // The code for starting the SDK. The following code is the code after the SDK is roughly encapsulated. 
                   OnscSharp.CreateProducer();
                   OnscSharp.StartProducer();
               }
               catch (Exception ex)
               {
               // Exception handling. 
               }
           }
           protected void Application_End(object sender, EventArgs e)
           {
               try
               {
                  // The code for stopping the SDK. 
                 OnscSharp.ShutdownProducer();
               }
               catch (Exception ex)
               { 
               // Exception handling. 
               }
           }
      }
    }                  
  5. Write and compile the test program.
  6. Save the DLL file of the SDK to the directory of the executable file or to the system directory and run the program. ddl
  7. Choose Tools > Options > Projects and Solutions > Web Projects. Then, select the Use the 64 bit version of IIS Express for websites and projects check box. iisexpressproject&sultion