# GetMsgQueSize

### int GetMsgQueSize()

GetMsgQueSize 함수는 현재 수신 메시지 큐(Queue)에 쌓여 있는 처리 대기 중인 메시지의 개수를 확인하고자 할 때 사용합니다.

장비와 호스트 사이의 통신량이 일시적으로 급증할 경우, 애플리케이션에서 `GetMsg` 등을 통해 아직 꺼내가지 않은 메시지가 얼마나 남아 있는지 모니터링하여 시스템의 부하 상태를 파악하는 용도로 매우 중요합니다.

### GetMsgQueSize() 주요 기능

1. 큐 모니터링: 라이브러리 내부 버퍼에 수신되어 파싱을 기다리고 있는 메시지의 총량을 반환합니다.
2. 병목 현상 감지: 이 값이 지속적으로 증가한다면, 애플리케이션의 메시지 처리 속도가 수신 속도를 따라가지 못하고 있다는 신호(Bottle-neck)로 해석할 수 있습니다.
3. 흐름 제어(Flow Control): 특정 임계치(Threshold)를 넘었을 때 경고를 발생시키거나 처리를 우선순위화하는 로직의 기준으로 활용됩니다.

#### Return Value

<table data-header-hidden><thead><tr><th width="236" valign="top"></th><th valign="top"></th></tr></thead><tbody><tr><td valign="top">Value</td><td valign="top">Description</td></tr><tr><td valign="top">>=0</td><td valign="top">Message Queue에 남은 Message수</td></tr></tbody></table>

```csharp
// 현재 대기 중인 메시지 개수 조회
    int nQueSize = m_gem.GetMsgQueSize();

    if (nQueSize >= 0)
    {
        Console.WriteLine($"현재 처리 대기 중인 메시지: {nQueSize}개");

        // 큐가 너무 많이 쌓였을 경우(예: 100개 이상) 경고 처리
        if (nQueSize > 100)
        {
            Console.WriteLine("[Warning] 메시지 처리 지연 발생! 처리 로직을 점검하십시오.");
        }
    }
    else
    {
        // nQueSize < -311 등 (실패 시)
        Console.WriteLine($"큐 사이즈 조회 실패. 에러 코드: {nQueSize}");
    }
```


---

# 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:

```
GET https://nviasoft.gitbook.io/nviasoft-docs/api-reference/item-parsing/getmsgquesize.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
