Skip to content

确认队列消息成功 - MessageQueueAck

函数简介

确认消息处理成功(Ack)。

接口名称

MessageQueueAck

DLL调用

c
int32_t MessageQueueAck(int64_t instance, int64_t consumer, int64_t delivery_tag);

参数说明

参数名类型说明
instance长整数型OLA 实例句柄。
consumer长整数型消费者句柄。
delivery_tag长整数型消息确认令牌(由回调或 Pull 返回)。

示例

SDK 调用

cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
// on_message=nullptr 时可配合 MessageQueuePull 主动拉取
long consumer = ola.MessageQueueConsume(1, 1, "127.0.0.1", 18890, "task_queue", nullptr);
if (consumer > 0) {
    std::string msg = ola.MessageQueuePull(consumer, 1000);
    ola.MessageQueueAck(consumer, ackToken);
    ola.MessageQueueCancel(consumer);
}
csharp
using OLAPlug;

var ola = new OLAPlugServer();
long consumer = ola.MessageQueueConsume(1, 1, "127.0.0.1", 18890, "task_queue", null);
if (consumer > 0)
{
    string msg = ola.MessageQueuePull(consumer, 1000);
    ola.MessageQueueAck(consumer, ackToken);
    ola.MessageQueueCancel(consumer);
}
python
from OLAPlugServer import OLAPlugServer

ola = OLAPlugServer()
consumer = ola.MessageQueueConsume(1, 1, "127.0.0.1", 18890, "task_queue", None)
if consumer > 0:
    msg = ola.MessageQueuePull(consumer, 1000)
    ola.MessageQueueAck(consumer, ack_token)
    ola.MessageQueueCancel(consumer)
java
import com.olaplug.OLAPlugServer;

OLAPlugServer ola = new OLAPlugServer();
long consumer = ola.MessageQueueConsume(1, 1, "127.0.0.1", 18890, "task_queue", null);
if (consumer > 0) {
    ola.MessageQueueAck(consumer, ackToken);
    ola.MessageQueueCancel(consumer);
}
cpp
var ola = com("OlaPlug.OlaSoft")
var consumer = ola.MessageQueueConsume(1, 1, "127.0.0.1", 18890, "task_queue", 0)
if(consumer > 0) {
    ola.MessageQueueAck(consumer, ackToken);
    ola.MessageQueueCancel(consumer)
}
vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
consumer = ola.MessageQueueConsume(1, 1, "127.0.0.1", 18890, "task_queue", 0)
If consumer > 0 Then
    ola.MessageQueueAck(consumer, ackToken);
    ola.MessageQueueCancel(consumer)
End If
text
.局部变量 ola, OLAPlug
ola.创建 ()
consumer = ola.MessageQueueConsume (1, 1, "127.0.0.1", 18890, "task_queue", 0)
.如果真 (consumer > 0)
    ola.MessageQueueAck(consumer, ackToken);
    ola.MessageQueueCancel (consumer)
.如果真结束
aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var consumer = ola.MessageQueueConsume(1, 1, "127.0.0.1", 18890, "task_queue", null);
if(consumer > 0){
    ola.MessageQueueAck(consumer, ackToken);
    ola.MessageQueueCancel(consumer);
}
text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
长整数 consumer = ola.MessageQueueConsume(1, 1, "127.0.0.1", 18890, "task_queue", 0)
如果真 (consumer > 0)
{
    ola.MessageQueueAck(consumer, ackToken);
    ola.MessageQueueCancel(consumer)
}
cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
long consumer = ola.MessageQueueConsume(1, 1, "127.0.0.1", 18890, "task_queue", nullptr);
if (consumer > 0) {
    ola.MessageQueueAck(consumer, ackToken);
    ola.MessageQueueCancel(consumer);
}

原生 DLL 调用

cpp
long instance = CreateCOLAPlugInterFace();
long consumer = MessageQueueConsume(instance, 1, 1, "127.0.0.1", 18890, "task_queue", 0);
if (consumer > 0) {
    long ptr = MessageQueuePull(instance, consumer, 1000);
    MessageQueueAck(instance, consumer, ackToken);
    MessageQueueCancel(instance, consumer);
}
csharp
using System.Runtime.InteropServices;
using System.Text;

[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long MessageQueueConsume(long ola, int type, int connect_type, string ip, int port, string queue_name, long callback);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int MessageQueueCancel(long ola, long consumer);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long MessageQueuePull(long ola, long consumer, int timeout_ms);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int MessageQueueAck(long ola, long consumer, long delivery_tag);

long instance = CreateCOLAPlugInterFace();
long consumer = MessageQueueConsume(instance, 1, 1, "127.0.0.1", 18890, "task_queue", 0);
if (consumer > 0) {
    long ptr = MessageQueuePull(instance, consumer, 1000);
    MessageQueueAck(instance, consumer, ackToken);
    MessageQueueCancel(instance, consumer);
}
python
from ctypes import CDLL, c_int, c_int64

ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
consumer = ola.MessageQueueConsume(instance, 1, 1, b"127.0.0.1", 18890, b"task_queue", 0)
if consumer:
    long ptr = ola.MessageQueuePull(instance, consumer, 1000);
    ola.MessageQueueAck(instance, consumer, ackToken);
    ola.MessageQueueCancel(instance, consumer)

返回值

返回值说明
(返回值)0 成功;<0 错误码。