# NATS & NATS Streaming - C Client
A C client for the [NATS messaging system](https://nats.io).
Go [here](http://nats-io.github.io/nats.c) for the online documentation,
and check the [frequently asked questions](https://github.com/nats-io/nats.c#faq).
This NATS Client implementation is heavily based on the [NATS GO Client](https://github.com/nats-io/nats.go). There is support for Mac OS/X, Linux and Windows (although we don't have specific platform support matrix).
[](https://www.apache.org/licenses/LICENSE-2.0)
[](https://travis-ci.com/github/nats-io/nats.c)
[](https://coveralls.io/github/nats-io/nats.c?branch=main)
[](https://github.com/nats-io/nats.c/releases/tag/v3.8.2)
[](http://nats-io.github.io/nats.c)
# Table of Contents
- [Installing](#installing)
- [Building](#building)
* [TLS Support](#tls-support)
* [Link statically](#link-statically)
* [Building with Streaming](#building-with-streaming)
* [Building with Libsodium](#building-with-libsodium)
* [Testing](#testing)
- [Documentation](#documentation)
- [NATS Client](#nats-client)
* [Important Changes](#important-changes)
* [JetStream](#jetstream)
* [JetStream Basic Usage](#jetstream-basic-usage)
* [JetStream Basic Management](#jetstream-basic-usage)
* [KeyValue](#keyvalue)
* [KeyValue Management](#keyvalue-management)
* [KeyValue APIs](#keyvalue-apis)
* [Getting Started](#getting-started)
* [Basic Usage](#basic-usage)
* [Headers](#headers)
* [Wildcard Subscriptions](#wildcard-subscriptions)
* [Queue Groups](#queue-groups)
* [TLS](#tls)
* [New Authentication (Nkeys and User Credentials)](#new-authentication-nkeys-and-user-credentials)
* [Advanced Usage](#advanced-usage)
* [Clustered Usage](#clustered-usage)
* [Using an Event Loop Library](#using-an-event-loop-library)
* [FAQ](#faq)
- [NATS Streaming Client](#nats-streaming-client)
* [Streaming Basic Usage](#streaming-basic-usage)
* [Streaming Subscriptions](#streaming-subscriptions)
* [Streaming Durable Subscriptions](#streaming-durable-subscriptions)
* [Streaming Queue Groups](#streaming-queue-groups)
* [Creating a Queue Group](#creating-a-queue-group)
* [Start Position](#start-position)
* [Leaving the Group](#leaving-the-group)
* [Closing a Queue Group](#closing-a-queue-group)
* [Streaming Durable Queue Groups](#streaming-durable-queue-groups)
* [Creating a Durable Queue Group](#creating-a-durable-queue-group)
* [Start Position of the Durable Queue Group](#start-position-of-the-durable-queue-group)
* [Leaving the Durable Queue Group](#leaving-the-durable-queue-group)
* [Closing the Durable Queue Group](#closing-the-durable-queue-group)
* [Streaming Wildcard Subscriptions](#streaming-wildcard-subscriptions)
* [Streaming Advanced Usage](#streaming-advanced-usage)
* [Connection Status](#connection-status)
* [Asynchronous Publishing](#asynchronous-publishing)
* [Message Acknowledgments and Redelivery](#message-acknowledgments-and-redelivery)
* [Rate limiting/matching](#rate-limitingmatching)
* [Publisher Rate Limiting](#publisher-rate-limiting)
* [Subscriber Rate Limiting](#subscriber-rate-limiting)
- [License](#license)
## Installing
There are several package managers with NATS C client library available. If you know one that is not in this list, please submit a PR to add it!
- [conan](https://conan.io/center) The "cnats" recipe is [here](https://github.com/conan-io/conan-center-index/tree/master/recipes/cnats)
- [Homebrew](https://github.com/Homebrew/homebrew-core) The "cnats" formula is [here](https://github.com/Homebrew/homebrew-core/blob/master/Formula/c/cnats.rb)
- [vcpkg](https://vcpkg.io) The "cnats" port is [here](https://github.com/microsoft/vcpkg/tree/master/ports/cnats)
## Building
First, download the source code:
```
git clone git@github.com:nats-io/nats.c.git .
```
To build the library, use [CMake](https://cmake.org/download/). Note that by default the NATS Streaming API will be built and included in the NATS library.
See below if you do not want to build the Streaming related APIs.
Make sure that CMake is added to your path. If building on Windows, open a command shell from the Visual Studio Tools menu, and select the appropriate command shell (x64 or x86 for 64 or 32 bit builds respectively). You will also probably need to run this with administrator privileges.
Create a `build` directory (any name would work) from the root source tree, and `cd` into it. Then issue this command for the first time:
```
cmake ..
```
In some architectures, you may experience a compilation error for `mutex.c.o` because there is no support
for the assembler instruction that we use to yield when spinning trying to acquire a lock.
You may get this sort of build error:
```
/tmp/cc1Yp7sD.s: Assembler messages:
/tmp/cc1Yp7sD.s:302: Error: selected processor does not support ARM mode `yield'
src/CMakeFiles/nats_static.dir/build.make:542: recipe for target 'src/CMakeFiles/nats_static.dir/unix/mutex.c.o' failed
```
If that's the case, you can solve this by enabling the `NATS_BUILD_NO_SPIN` flag (or use `-DNATS_NO_SPIN` if you compile without CMake):
```
cmake .. -DNATS_BUILD_NO_SPIN=ON
```
If you had previously built the library, you may need to do a `make clean`, or simply delete and re-create the build directory before executing the cmake command.
To build on Windows, you would need to select the build generator. For instance, to select `nmake`, you would run:
```
cmake .. -G "NMake Makefiles"
```
Running `cmake -h` would give you the list of possible options and all the generator names.
Alternatively, you can run the GUI version. From that same *build* command shell, start the GUI:
```
c:\program files (x86)\CMake\bin\cmake-gui.exe
```
If you started with an empty build directory, you would need to select the source and build directory, then click `Configure`. Here, you will be able to select from the drop-down box the name of the build generator. When done, click `Generate`. Then you can go back to your command shell, or Visual Studio and build.
To modify some of the build options, you need to edit the cache and rebuild.
```
make edit_cache
```
Note that if you build on Windows and have selected "NMake Makefiles", replace all following references to `make` with `nmake`.
Editing the cache allows you to select the build type (Debug, Release, etc), the architecture (64 or 32bit), and so on.
The default target will build everything, that is, the static and shared NATS libraries and also the examples and the test program. Each are located in their respective directories under your build directory: `src`, `examples` and `test`.
```
make install
```
Will copy both the static and shared libraries in the folder `install/lib` and the public headers in `install/include`.
## TLS Support
By default, the library is built with TLS support. You can disable this from the cmake gui `make edit_cache` and switch the `NATS_BUILD_WITH_TLS` option to `OFF`, or pass the option directly to the `cmake` command:
```
cmake .. -DNATS_BUILD_WITH_TLS=OFF
```
Starting `2.0.0`, when building with TLS/SSL support, the server certificate's expected hostname is always verified. It means that the hostname provided in the URL(s) or through the option `natsOptions_SetExpectedHostname()` will be used to check the hostname present in the certificate. Prior to `2.0.0`, the hostname would be verified *only* if the option `natsOptions_SetExpectedHostname()` was invoked.
Although we recommend leaving the new default behavior, you can restore the previous
nats.c-main.zip
需积分: 0 68 浏览量
更新于2024-08-22
收藏 1.92MB ZIP 举报
nats.c-main.zip

相由心生901
- 粉丝: 0
- 资源: 1
最新资源
- matlab实现四旋翼无人机自抗扰姿态容错控制-飞行器控制-四旋翼无人机-自抗扰控制-UAV-扰动识别-matlab
- 基于主从博弈的综合能源微网与共享储能优化运行研究:迭代算法探索与利益相关者的博弈策略,基于主从博弈的综合能源微网与共享储能优化运行研究:电价策略与用户行为互动,matlab 代码基于主从博弈的共享储能
- 14章RAG全栈技术从基础到精通 ,打造高精准AI应用
- MATLAB平台下的多目标粒子群算法在冷热电联供综合能源系统优化中的实践,基于多目标粒子群算法的冷热电联供综合能源系统优化调度模型,MATLAB代码:基于多目标粒子群算法冷热电联供综合能源系统运行优化
- 三相桥式全控整流及其有源逆变与Simulink仿真波形分析(含不同触发角和负载变化图),三相桥式全控整流及其有源逆变与Simulink仿真探究:触发角与负载变化下的波形图分析,三相桥式全控整流及其有源
- 中国智能制造装备产业发展机遇蓝皮书 2024.pdf
- 【毕业设计】Python的Django-html网易新闻+评论的舆情热点分析平台源码(完整前后端+mysql+说明文档+LW+PPT).zip
- 西门子1200 PLC与昆仑通态上位软件结合的新能源物料输送系统程序案例解析,V16+博图版本,RS485通讯控制托利多称重仪表模拟量读取技术实现,西门子S1200博图物料输送系统:新能源物料输送PL
- 【毕业设计】Python的Django-html图像的信息隐藏技术研究源码(完整前后端+mysql+说明文档+LW+PPT).zip
- 【毕业设计】Python的Django-html深度学习的车牌识别系统源码(完整前后端+mysql+说明文档+LW+PPT).zip
- 【毕业设计】Python的Django-html深度学习屋内烟雾检测方法源码(完整前后端+mysql+说明文档+LW+PPT).zip
- 灰狼算法在微电网优化调度中的应用:考虑风光储与需求响应的多元经济优化策略,模型可塑性强且出图丰富的实践研究,灰狼算法在微电网风光储需求响应优化调度中的应用:经济性优化与模型可塑性的研究分析图集,灰狼算
- 【毕业设计】Python的Django-html人脸识别的实验室智能门禁系统源码(完整前后端+mysql+说明文档+LW+PPT).zip
- 【毕业设计】Python的Django-html深度学习的身份证识别考勤系统源码(完整前后端+mysql+说明文档+LW+PPT).zip
- 【毕业设计】Python的Django-html时间序列分析的大气污染预测系统源码(完整前后端+mysql+说明文档+LW+PPT).zip
- matlab实现遗传算法在物流中心配送路径规划中的应用-遗传算法-路径规划-物流配送-最佳配送方案-matlab