github.com/safedep/dry@v0.0.0-20241016050132-a15651f0548b/async/messaging.go (about)

     1  package async
     2  
     3  import (
     4  	"context"
     5  	"time"
     6  )
     7  
     8  // Application defined handler function for incoming messages
     9  type MessageHandler func(context.Context, []byte) error
    10  
    11  type ClosableMessagingService interface {
    12  	Close() error
    13  }
    14  
    15  // Interface for a subscribed queue
    16  type MessagingQueueSubscription interface {
    17  	Unsubscribe() error
    18  }
    19  
    20  // Low level messaging service interface
    21  type MessagingService interface {
    22  	ClosableMessagingService
    23  
    24  	Publish(ctx context.Context, topic string, data []byte) error
    25  	QueueSubscribe(topic string, queue string, callback MessageHandler) (MessagingQueueSubscription, error)
    26  }
    27  
    28  // Async request response service interface
    29  type AsyncRequestResponseService interface {
    30  	ClosableMessagingService
    31  
    32  	Request(ctx context.Context, topic string, data []byte, timeout time.Duration) ([]byte, error)
    33  }