Documentation
¶
Overview ¶
Package notify provides PostgreSQL LISTEN/NOTIFY functionality for real-time notifications.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChannelMessageNotification ¶
type ChannelMessageNotification struct {
ChannelName string `json:"channel_name"`
MessageID int64 `json:"message_id"`
TargetInstanceID string `json:"target_instance_id,omitempty"`
}
ChannelMessageNotification is the payload for channel message notifications.
func ParseChannelMessageNotification ¶
func ParseChannelMessageNotification(payload string) (*ChannelMessageNotification, error)
ParseChannelMessageNotification parses a channel message notification payload.
type Listener ¶
type Listener struct {
// contains filtered or unexported fields
}
Listener manages PostgreSQL LISTEN/NOTIFY connections.
func NewListener ¶
func NewListener(connString string, opts ...ListenerOption) *Listener
NewListener creates a new PostgreSQL notification listener.
func (*Listener) OnNotification ¶
func (l *Listener) OnNotification(channel NotifyChannel, handler NotificationHandler)
OnNotification registers a handler for a notification channel. Multiple handlers can be registered for the same channel.
type ListenerOption ¶
type ListenerOption func(*Listener)
ListenerOption configures a Listener.
func WithReconnectDelay ¶
func WithReconnectDelay(d time.Duration) ListenerOption
WithReconnectDelay sets the delay before reconnecting after a connection failure.
type NotificationHandler ¶
type NotificationHandler func(ctx context.Context, channel NotifyChannel, payload string)
NotificationHandler is a callback function that handles notifications.
type NotifyChannel ¶
type NotifyChannel string
NotifyChannel represents a PostgreSQL notification channel name.
const ( // ChannelWorkflowResumable is notified when a workflow becomes resumable. ChannelWorkflowResumable NotifyChannel = "romancy_workflow_resumable" // ChannelTimerExpired is notified when a timer is registered. ChannelTimerExpired NotifyChannel = "romancy_timer_expired" // ChannelChannelMessage is notified when a channel message is published. ChannelChannelMessage NotifyChannel = "romancy_channel_message" // ChannelOutboxPending is notified when an outbox event is added. ChannelOutboxPending NotifyChannel = "romancy_outbox_pending" )
func AllChannels ¶
func AllChannels() []NotifyChannel
AllChannels returns all notification channels.
type OutboxNotification ¶
type OutboxNotification struct {
EventID string `json:"event_id"`
}
OutboxNotification is the payload for outbox pending notifications.
func ParseOutboxNotification ¶
func ParseOutboxNotification(payload string) (*OutboxNotification, error)
ParseOutboxNotification parses an outbox notification payload.
type TimerNotification ¶
type TimerNotification struct {
InstanceID string `json:"instance_id"`
TimerID string `json:"timer_id"`
ExpiresAt string `json:"expires_at,omitempty"`
}
TimerNotification is the payload for timer expired notifications.
func ParseTimerNotification ¶
func ParseTimerNotification(payload string) (*TimerNotification, error)
ParseTimerNotification parses a timer notification payload.
type WorkflowNotification ¶
type WorkflowNotification struct {
InstanceID string `json:"instance_id"`
WorkflowName string `json:"workflow_name,omitempty"`
}
WorkflowNotification is the payload for workflow resumable notifications.
func ParseWorkflowNotification ¶
func ParseWorkflowNotification(payload string) (*WorkflowNotification, error)
ParseWorkflowNotification parses a workflow notification payload.