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

Handler for reconnection errors #34

Closed
tiggerite opened this issue Jun 1, 2022 · 1 comment
Closed

Handler for reconnection errors #34

tiggerite opened this issue Jun 1, 2022 · 1 comment

Comments

@tiggerite
Copy link
Contributor

tiggerite commented Jun 1, 2022

Currently there is no way to handle when reconnection is failing, and there is no feedback for logs either for Splunk logging and so forth. Even this wouldn't really be enough on its own as without a handling mechanism, it's not possible to write metrics for these errors to enable alerting and so on.

I've carefully crafted this PR to allow for this extra handler, which can be hooked into by first creating a ConnectionPool via the new NewConnectionPoolWithUnhealthyHandler or NewConnectionPoolWithHandlers "constructors" and then passing this into the new NewRabbitServiceWithConnectionPool "constructor" for the rabbit service. This way, no existing underlying logic changes and there are no breaking API changes either.

Simple example of the latter in action.

		connectionPool, err := tcr.NewConnectionPoolWithHandlers(poolConfig, processError, processUnhealthy)
		if err != nil {
			fmt.Printf("error during setup connection pool: %s", err.Error())
			panic(err)
		}

		var seasoning = &tcr.RabbitSeasoning{
			PoolConfig:      poolConfig,
			ConsumerConfigs: consumerConfigs,
			PublisherConfig: publisherConfig,
			EncryptionConfig:  &tcr.EncryptionConfig{},
			CompressionConfig: &tcr.CompressionConfig{},
		}

		rs, err := tcr.NewRabbitServiceWithConnectionPool(connectionPool, seasoning, "", "", nil, nil)
func processError(err error) {
	fmt.Printf("%s: Rabbit consumer - Error: %s\r\n", time.Now(), err)
}

func processUnhealthy(err error) {
	fmt.Printf("%s: Rabbit connection unhealthy - Error: %s\r\n", time.Now(), err)
}
@houseofcat
Copy link
Owner

Thanks for your enthusiasm :)

Been really busy with life and I have finally got to resetting up Golang/Erlang/VsCode/RabbitMQ on my home computer.

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

No branches or pull requests

2 participants