在windows2012上安装Message Queuing(域模式)

本文档详细介绍了如何在Windows Server 2012上安装Message Queuing(MSMQ)服务,并强调了在域模式下进行安装的关键步骤,包括设置网络服务权限,以及在域控制服务器和客户机上的配置过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

35/100发布文章 博文管理我的博客退出 Trash Temp 在windows2012上安装Message Queuing(域模式) 添加摘要 @[MSMQ]
在windows2012上安装Message Queuing(域模式)
在windows2012上安装Message Queuing(域模式)

  1. Windows2012 上安装域控制(AD DC);
  2. 域控制服务器上需先设置network service权限(这点是关键,否则后面安装MSMQ服务的机器工作会不正常)

Click Start , point to Programs , point to Administrative Tools , and then click Active Directory Users and Computers to open Active Directory Users and Computers .

Click the View menu and click to enable the options for Users, Groups, and Computers as containers and Advanced Features .

Click to expand the Domain container for the domain, click to expand the Computers container, right-click the computer object on which the Directory Services Integration feature is being installed, and then clickProperties to display the computer properties dialog box.

Click to select the Security tab of the computer properties dialog box.

Click the Advanced button to display the Advance

### 如何在 C++ 中集成和使用 Microsoft Message Queue (MSMQ) Microsoft Message Queue (MSMQ) 是一种消息队列技术,允许应用程序通过发送和接收消息来进行通信。它支持跨网络的消息传递,并能在不可靠的环境中提供可靠的消息交付机制。 以下是关于如何在 C++ 中集成和使用 MSMQ 的详细介绍: #### 1. 安装和配置 MSMQ 为了能够在 Windows 上使用 MSMQ,需要先安装并启用该服务。可以通过以下步骤完成: - 打开“控制面板” -> “程序和功能” -> “启用或关闭 Windows 功能”。 - 勾选“Message Queuing”及其子项[^3]。 此外,在进行远程调试时需要注意一些额外的安全设置,例如取消服务器安全性的限制以及为队列分配适当的权限[^3]。 #### 2. 编程接口概述 MSMQ 提供了一个 COM 接口用于开发人员编写客户端应用。C++ 开发者通常会利用 MFC 或 ATL 库来简化对 COM 对象的操作过程。主要涉及以下几个类: - `IMSMQQueue`:表示单个消息队列实例。 - `IMSMQMessage`:定义了一条具体的消息对象。 - `IMSMQCoordinatedTransactionDispenser` 和其他事务相关组件(可选)。 #### 3. 创建一个简单的消息发送与接收示例 下面是完整的 C++ 示例代码展示如何向本地公共队列发送一条测试消息再将其读回显示出来。 ```cpp #include <windows.h> #include <mq.h> // MSMQ header file #include <atlbase.h> // For CComPtr #include <iostream> // Initialize COM library before using any MSMQ functions. void InitCOM() { HRESULT hr = CoInitialize(NULL); if (FAILED(hr)) { std::cerr << "Failed to initialize COM library." << std::endl; exit(1); } } int main() { try { InitCOM(); // Define queue path name and create a pointer to IMSMQQueue interface. const wchar_t* QUEUE_PATHNAME = L".\\public$\MyTestQueue"; CComPtr<IMSMQQueueInfo> spQueueInfo; HRESULT hr = spQueueInfo.CoCreateInstance(CLSID_MSMQQueueInfo); if (SUCCEEDED(hr)) { spQueueInfo->put_PathName(QUEUE_PATHNAME); VARIANT vOpenFlags, vAccess, vShareMode; VariantInit(&vOpenFlags), VariantInit(&vAccess), VariantInit(&vShareMode); vOpenFlags.vt = VT_I4; vOpenFlags.lVal = MQ_SEND_ACCESS | MQ_RECEIVE_ACCESS; vAccess.vt = VT_UI4; vAccess.ulVal = MQ_DENY_NONE; vShareMode.vt = VT_UI4; vShareMode.ulVal = 0; CComPtr<IMSMQQueue> spQueue; hr = spQueueInfo->Open(vOpenFlags, vAccess, &spQueue); if (SUCCEEDED(hr)) { // Create message object CComPtr<IMSMQMessage> spMsg; hr = spMsg.CoCreateInstance(__uuidof(MSMQMessage)); if (SUCCEEDED(hr)) { BSTR bstrLabel = SysAllocString(L"Test Label"); spMsg->put_Label(bstrLabel); SAFEARRAY *psaBody = SafeArrayCreateVector(VT_UI1, 0, strlen("Hello MSMQ!")); char data[] = "Hello MSMQ!"; memcpy(SafeArrayGetPV(psaBody, NULL), data, sizeof(data)-1); spMsg->put_Body(psaBody); SysFreeString(bstrLabel); SafeArrayDestroy(psaBody); // Send the message spMsg->Send(spQueue); printf("Message sent successfully.\n"); // Receive the same message back immediately as an example of receiving messages CComVariant varReceiveTimeout; varReceiveTimeout.vt = VT_I4; varReceiveTimeout.intVal = 5000; // Timeout set at 5 seconds CComPtr<IMSMQMessage> spReceivedMsg; hr = spQueue->Receive(varReceiveTimeout, NULL, NULL, NULL, &spReceivedMsg); if (SUCCEEDED(hr)) { long cbDataSize; BYTE* pDataBuffer; spReceivedMsg->get_Body(&psaBody); SafeArrayAccessData(psaBody, reinterpret_cast<void**>(&pDataBuffer)); SafeArrayGetUBound(psaBody, 1, &cbDataSize); for(int i=0;i<=cbDataSize;i++) putchar(*(pDataBuffer+i)); puts(""); SafeArrayUnaccessData(psaBody); SafeArrayDestroy(psaBody); } else { printf("No message received within timeout period or error occurred during reception."); } spQueue->Close(); } } else { printf("Could not open specified queue %ls\n", QUEUE_PATHNAME); } } CoUninitialize(); } catch (...) { std::cout << "An exception was caught!" << std::endl; } return 0; } ``` 以上代码展示了基本的功能实现方法,包括初始化 COM 环境、打开目标队列、构建消息体并通过指定路径名发送出去;同时也演示了即时获取刚发出的信息作为验证手段之一。 #### 注意事项 - **异常处理**:实际项目中应更加注重各种可能发生的错误情况下的优雅降级策略。 - **性能优化**:当面对高吞吐量需求场景下考虑采用批量操作等方式提升效率。 - **安全性考量**:确保只有授权用户才能访问敏感数据所在的队列资源[^3]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值