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

[WIP] Synchronous and Asynchronous reconnection #79

Open
wants to merge 3 commits into
base: reconnection-sink
Choose a base branch
from

Conversation

fenos
Copy link

@fenos fenos commented Nov 7, 2018

Reconnection Proposal

When NATS or others MessageBrokers loses connection permanently we are unable to re-establish a connection.

This PR will allow to you to opt in for the abstract ReconnectorSink which will handle re-connection logic for your MessageBroker.

The implementation allows you to chose between Asynchronous or Synchronous reconnection logic.

  • Asynchronous (Default): When losing some messages it's not a big deal
  • Synchronous: When loosing messages it's a big deal!

Example Usage:

	sink, err := instrumented.NewReconnectorSink(
		natss.ErrConnLost, // The error which identify a Connection Lost
		func() (pubsub.MessageSink, error) { // Function that returns your interested Sink
			// You can return any SINK you'd like
			return natss.NewMessageSink(
				natss.MessageSinkConfig{
					NatsURL:   url,
					ClusterID: clusterID,
					ClientID:  clientID,
					Topic:     topic,
				},
			)
		},
		&instrumented.ReconnectionOptions{
			ReconnectSynchronously: false,
			OnReconnectFailed: func(error) {
				// Logging
			},
			OnReconnectSuccess: func(sink pubsub.MessageSink, err error) {
				// Do Somenthing
			},
		},
	)

connects to utilitywarehouse/crm/issues/152

mq.retryStrategy(nil)
mq.Unlock()
return mq.Status()
} else {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if block ends with a return statement, so drop this else and outdent its block

mq.retryStrategy(nil)
mq.Unlock()
return mq.sink.PutMessage(m)
} else {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if block ends with a return statement, so drop this else and outdent its block

@fenos fenos force-pushed the reconnection-sink-implementation branch from ea2b616 to a346131 Compare November 7, 2018 15:56
@denislobanov
Copy link
Contributor

I think this could be really useful, but I can't help but wonder why is Async default? Given the explanation that async allows for message loss; would it not be more sensible to set default to synchronous?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants