All Products
Search
Document Center

ApsaraMQ for RocketMQ:Prepare the .NET SDK environment

Last Updated:Mar 11, 2026

Set up the ApsaraMQ for RocketMQ TCP client SDK for .NET to send and receive messages from a Windows application.

SDK architecture

The ApsaraMQ for RocketMQ SDK for .NET is a managed wrapper around the C++ SDK. It uses C++ multi-thread concurrent processing for high efficiency and stability while remaining independent of the public library of the Windows SDK for .NET.

When Visual Studio compiles a .NET project, the default target platform is AnyCPU, which auto-selects x86 or x64 based on the CPU type. At runtime, the Just-in-Time (JIT) compiler in the .NET Common Language Runtime (CLR) converts Intermediate Language (IL) code into x86 or x64 machine code. The underlying C or C++ DLL is compiled as x64 machine code. Therefore, the SDK ships a 64-bit DLL in release mode, built with Visual Studio 2015 and .NET Framework 4.5.2. This 64-bit DLL is compatible with other Visual Studio versions.

Important
  • The SDK supports only the Windows 64-bit operating system.

  • The C++ DLL requires the Visual C++ 2015 runtime. If the runtime is not installed, run the vc_redist.x64.exe installer included in the SDK package.

Prerequisites

Before you begin, make sure that you have:

  • An Alibaba Cloud Elastic Compute Service (ECS) instance to deploy your application

  • A Windows 64-bit operating system

  • Visual Studio 2015 (the 64-bit DLL is also compatible with other Visual Studio versions)

  • .NET Framework 4.5.2

  • The Visual C++ 2015 runtime (install vc_redist.x64.exe from the SDK package if not already present)

  • Topics and group IDs created in the ApsaraMQ for RocketMQ console (message tags can be specified in your application code)

Download the SDK

We recommend that both new users and existing users who are not concerned with upgrade costs download the latest version of the SDK for .NET from the release notes page.

After you extract the package, the directory structure is as follows:

Directory or file

Description

lib/

Underlying C++ DLL files and the Visual C++ 2015 runtime installer

lib/64/ONSClient4CPP.lib

C++ static library

lib/64/ONSClient4CPP.dll

C++ dynamic library

lib/64/ONSClient4CPP.pdb

Debug symbols

lib/vc_redist.x64.exe

Visual C++ 2015 runtime installer

demo/

Sample code for sending normal, one-way, and ordered messages, and for consuming normal and ordered messages

interface/

PInvoke wrapper code (must be included in your project)

SDK_GUIDE.pdf

SDK environment setup guide and FAQ

changelog

Bug fixes and new features per release

File names in the lib/ directory may vary depending on the SDK version.

Set up a .NET console project

  1. Create a project in Visual Studio.

    Create project

  2. Add the PInvoke wrapper files: right-click the project, choose Add > Add Existing Item, and select all files from the interface/ directory of the extracted SDK package.

    Add interface files

  3. Set the build configuration: right-click the project, choose Properties > Configuration Manager, then set Active solution configuration to Release and Active solution platform to x64.

  4. Write and compile your application, then copy the SDK DLL files to the output directory of the executable (or to a system directory) and run the program.

    DLL files in output directory

The SDK includes a preconfigured demo project that you can open and compile directly. Before running it, copy the required DLL files to the directory of the executable. Copy DLL files

Set up an ASP.NET Web Forms project

  1. Create a Web Forms project for ASP.NET in Visual Studio.

    Create Web Forms project

  2. Set the build configuration: right-click the project, choose Properties > Configuration Manager, then set Active solution configuration to Release and Active solution platform to x64.

    Set platform to x64

  3. Add the PInvoke wrapper files: right-click the project, choose Add > Add Existing Item, and select all files from the interface/ directory of the extracted SDK package. For details, see Step 2 in Set up a .NET console project.

  4. Add SDK startup and shutdown code to the Global.asax.cs file. The following example starts the producer when the application starts and shuts it down when the application ends:

       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;    // SDK namespace
       using test;   // Wrapper classes namespace
    
       namespace WebApplication4
       {
           public class Global : HttpApplication
           {
               void Application_Start(object sender, EventArgs e)
               {
                   // Standard ASP.NET startup
                   RouteConfig.RegisterRoutes(RouteTable.Routes);
                   BundleConfig.RegisterBundles(BundleTable.Bundles);
    
                   try
                   {
                       // Initialize and start the producer
                       OnscSharp.CreateProducer();
                       OnscSharp.StartProducer();
                   }
                   catch (Exception ex)
                   {
                       // Handle initialization errors
                   }
               }
    
               protected void Application_End(object sender, EventArgs e)
               {
                   try
                   {
                       // Shut down the producer gracefully
                       OnscSharp.ShutdownProducer();
                   }
                   catch (Exception ex)
                   {
                       // Handle shutdown errors
                   }
               }
           }
       }
  5. Write and compile the application.

  6. Copy the SDK DLL files to the output directory of the executable (or to a system directory) and run the program.

    DLL files for ASP.NET project

  7. Enable 64-bit IIS Express: choose Tools > Options > Projects and Solutions > Web Projects, then select the Use the 64 bit version of IIS Express check box.

    IIS Express settings

    Projects and Solutions settings

What's next

After you set up the environment, use the sample code in the demo/ directory to send and receive messages. For more information about how to create topics, group IDs, and message tags, see Create resources.