ONS C + + Windows SDK debugging methods and considerations

Source: Internet
Author: User
Tags aliyun

This article will show the entire debugging process for the ONS C + + Windows SDK, where I send sample code directly using the example message in the SDK package, the development environment is Win7, 64-bit, Visual Studio Professional 2013 (version 12.0.21005.1 REL).

Download the latest SDK package (published in the Code for October 14, 2015) and unzip it (local save directory is d:\doc\ons\c++\aliyun-ons-client-cpp-windows).

Before commissioning, please read the instructions in detail using the documentation aliyun_ons_client_for_cpp_and_net_user_guide.

The Include provides header files, and Lib provides 32-bit and 64-bit dependent packages (ONSClient4CPP.dll, ONSClient4CPP.lib, ONSCLIENT4CPP.PDB), example provides sample code for message sending and message consumption, and this article uses the message to send the sample code.

1. New Project

OK, click Next.

Click Done and the project has been created.

2. Create the source file and introduce the header file

source files, add new items, and copy Producerexampleforex content from example.

Header file, add an existing item, and add all the header files in the Include folder.

The project right-click Property->c/c++-> General, additional include directory, contains the header file directory d:\doc\ons\c++\aliyun-ons-client-cpp-windows\include.

Linker---general---attachment library directory, containing the ONSClient4CPP.lib directory d:\doc\ons\c++\aliyun-ons-client-cpp-windows\lib\32 bit.

The above settings are for 32-bit, if the user needs to debug 64-bit, then you need to click on Configuration Manager, new x64 platform, and 64-bit ONSClient4CPP.lib in the directory included, such as.

Add-on dependency, input, linker, ONSClient4CPP.lib.

3. Other Settings

C/c++-> code generation, basic run-time checks, set to default values.

Embedded list, input and output, inventory tools, set to No.

4. Build a Solution

The solution chosen here is configured as debug, and you can see that the corresponding executable file ONSdemo.exe has been generated under the directory D:\Program Files\vsproject\onsdemo\debug, and you can see some warn, One is that the warning needs to call ONSClient4CPP.dll (see 5), and the second is that the warning does not handle the exception e (the user needs to add the robustness of the program according to his business, followed by the logic of handling the exception).

5. Calling the DLL

Place the onsclient4cpp.dll,onsclient4cpp.pdb and ONSdemo.exe in the same directory D:\Program files\vsproject\onsdemo\debug.

Msvcp120.dll and Msvcr120.dll in the SDK package are vs components, which are typically found in the C:\Windows\System32 after installing vs locally, and if not, do not worry about copying the two DLLs in the SDK package to the C:\Windows\ System32 or ONSdemo.exe are located in the same directory.

6. Start debugging

Before starting debugging, according to the user's own data, modify Parameters Producerid, topic, AccessKey, Secretkey.

Factoryinfo.setfactoryproperty (onsfactoryproperty::P roducerid, "pid_xxxxxxxx");//Producerid applied at ONS console
Factoryinfo.setfactoryproperty (onsfactoryproperty::P ublishtopics, "xxxxxxxxx");//msg topic applied at ONS console
Factoryinfo.setfactoryproperty (onsfactoryproperty::msgcontent, "Input msg content");//Message contents
Factoryinfo.setfactoryproperty (Onsfactoryproperty::accesskey, "xxx");//ons AccessKey
Factoryinfo.setfactoryproperty (Onsfactoryproperty::secretkey, "xxxxxxxxx");//ONS Secretkey

Producerid, topic need to be created in the console in advance, the topic of the public environment can be tested locally, otherwise it needs to be deployed on the corresponding GEO ECS to use the ONS service normally.

After you start debugging, no exception is thrown, indicating that the message was sent successfully.

7. Verify that the message was sent successfully

It is recommended to set the key property in the message so that the key value is used to query the message on the console.

For example: Msg.setkey ("onsdemotest");

Here again, 32-bit or 64-bit dependent packet onsclient4cpp introduction and WIN32, the choice of x64 platform must be consistent; In addition, if you use other versions of VS, you need to be careful and consistent with the parameter values in other settings in the article.

ONS C + + Windows SDK debugging methods and considerations

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.