> For the complete documentation index, see [llms.txt](https://tarscloud.gitbook.io/tarsdocs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tarscloud.gitbook.io/tarsdocs/tarscpp/tars_queue.md).

# 队列模式

### 背景

目前的服务端模型中, 默认情况下, 请求过来时, 服务端业务处理线程谁空闲谁来处理当前请求, 因此同一个链接的请求可能被任何一个线程处理.

但是在某些场合下, 我们希望同一个链接的请求都被同一个线程执行, 从而保证连接上请求的有序性, 我们可以启用队列模式来实现这个能力.

### 使用方式

我们在服务的`initialize`中执行:

```c++
//注意tarscpp版本,老版本可能没有这个函数
getBindAdapter(ServerConfig::Application + "." + ServerConfig::ServerName +".HelloObj")->enableQueueMode();

//如果3.0.15之前的版本, 可以如下:
getEpollServer()->getBindAdapter(ServerConfig::Application + "." + ServerConfig::ServerName +".HelloObjAdapter")->enableQueueMode();

```

总之, 你需要获取到服务的BindAdapter, 然后通过bindAdapter来启用队列模式.

执行后, 队列模式则被启用.

### 注意

* 如果服务模型是: NET\_THREAD\_MERGE\_HANDLES\_CO or NET\_THREAD\_MERGE\_HANDLES\_THREAD, 这两种模式下, 网络线程和业务处理线程其实是一个, 这时候默认就启用了队列模式


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://tarscloud.gitbook.io/tarsdocs/tarscpp/tars_queue.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
