async_nats/
message.rs

1// Copyright 2020-2023 The NATS Authors
2// Licensed under the Apache License, Version 2.0 (the "License");
3// you may not use this file except in compliance with the License.
4// You may obtain a copy of the License at
5//
6// http://www.apache.org/licenses/LICENSE-2.0
7//
8// Unless required by applicable law or agreed to in writing, software
9// distributed under the License is distributed on an "AS IS" BASIS,
10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11// See the License for the specific language governing permissions and
12// limitations under the License.
13
14//! A Core NATS message.
15use bytes::Bytes;
16use serde::{Deserialize, Serialize};
17
18use crate::header::HeaderMap;
19use crate::status::StatusCode;
20use crate::subject::Subject;
21
22/// A Core NATS message.
23#[derive(Clone, Debug, Serialize, Deserialize)]
24pub struct Message {
25    /// Subject to which message is published to.
26    pub subject: Subject,
27    /// Optional reply subject to which response can be published by [crate::Subscriber].
28    /// Used for request-response pattern with [crate::Client::request].
29    pub reply: Option<Subject>,
30    /// Payload of the message. Can be any arbitrary data format.
31    pub payload: Bytes,
32    /// Optional headers.
33    pub headers: Option<HeaderMap>,
34    /// Optional Status of the message. Used mostly for internal handling.
35    pub status: Option<StatusCode>,
36    /// Optional [status][crate::Message::status] description.
37    pub description: Option<String>,
38
39    pub length: usize,
40}