55from typing import TypeAlias , TypeVar
66from collections .abc import AsyncIterable , Callable
77
8- from pynumaflow ._constants import DROP
8+ from pynumaflow ._constants import DROP , NACK
9+ from pynumaflow ._nack import NackOptions
910from pynumaflow ._validate import _validate_message_fields
1011
1112M = TypeVar ("M" , bound = "Message" )
@@ -27,6 +28,7 @@ class Message:
2728 _value : bytes
2829 _keys : list [str ]
2930 _tags : list [str ]
31+ _nack_options : NackOptions | None
3032
3133 def __init__ (self , value : bytes , keys : list [str ] | None = None , tags : list [str ] | None = None ):
3234 """
@@ -36,12 +38,23 @@ def __init__(self, value: bytes, keys: list[str] | None = None, tags: list[str]
3638 self ._keys = keys or []
3739 self ._tags = tags or []
3840 self ._value = value or b""
41+ self ._nack_options = None
3942
4043 # returns the Message Object which will be dropped
4144 @classmethod
4245 def to_drop (cls : type [M ]) -> M :
4346 return cls (b"" , None , [DROP ])
4447
48+ @classmethod
49+ def to_nack (cls : type [M ], opts : NackOptions | None = None ) -> M :
50+ m = cls (b"" , None , [NACK ])
51+ m ._nack_options = opts
52+ return m
53+
54+ @property
55+ def nack_options (self ) -> NackOptions | None :
56+ return self ._nack_options
57+
4558 @property
4659 def value (self ) -> bytes :
4760 return self ._value
0 commit comments