Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#61 Restart response router loop after error #62

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions rpc/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ type (
amqpReceiver interface {
Receive(ctx context.Context) (*amqp.Message, error)
Close(ctx context.Context) error
IsAlive() bool
}

amqpSender interface {
Expand Down Expand Up @@ -219,6 +220,7 @@ func (l *Link) RetryableRPC(ctx context.Context, times int, delay time.Duration,
// link and forwarding it to the proper channel. The channel is being select'd by the
// original `RPC` call.
func (l *Link) startResponseRouter() {
defer func() { l.startResponseRouterOnce = &sync.Once{} }()
for {
res, err := l.receiver.Receive(context.Background())

Expand Down Expand Up @@ -501,3 +503,9 @@ func isClosedError(err error) bool {
errors.Is(err, amqp.ErrConnClosed) ||
errors.Is(err, amqp.ErrSessionClosed)
}

// IsAlive returns false if the link is closed or if it is
// in a detached state, and returns true otherwise
func (l *Link) IsAlive() bool {
return l.receiver.IsAlive()
}