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

Support for activemq failover protocol #23

Open
pariz opened this issue Aug 26, 2016 · 5 comments
Open

Support for activemq failover protocol #23

pariz opened this issue Aug 26, 2016 · 5 comments
Labels

Comments

@pariz
Copy link

pariz commented Aug 26, 2016

Would it be reasonable to implement the activemq failover protocol?
I'm thinking about doing this myself, but i'm not sure if it's relevant to the project or if it should be made separately.

@worg
Copy link
Collaborator

worg commented Aug 26, 2016

A failover helper would be nice, returning a net.Conn for later use with Connect, I'm a little worried about the semantics of ActiveMQ failover but I think it can be solved.
It would be great if you could send a PR with the helper.
Thanks!

Sorry, mistakenly closed the issue.

@worg worg closed this as completed Aug 26, 2016
@worg worg reopened this Aug 26, 2016
@pariz
Copy link
Author

pariz commented Aug 31, 2016

Absolutely.
Perhaps a Failover method that takes a slice of Conn structs, spawns a goroutine for each connection and sends a failover request through a channel if it goes down.

@worg worg added the stale label Jan 24, 2017
@worg worg closed this as completed Dec 18, 2017
@johnjelinek
Copy link

I think this is still something that should be prioritized. Can you please re-open this issue?

@worg worg reopened this May 16, 2019
@worg
Copy link
Collaborator

worg commented May 16, 2019

Reopening the issue is the first step, PRs are very welcome in case anyone would want to tackle the issue (:

@johnjelinek
Copy link

Not sure if this can be retrofitted, but I implemented poor-man's failover in my application with this:

// isSTOMPTLS determines whether the address should use TLS nor not
func isSTOMPTLS(address string) bool {
	_, port, err := net.SplitHostPort(address)
	if err != nil {
		return false
	}

	switch port {
		case "61613":
			return false
		case "61614":
			return true
		default:
			return false
	}
}

// connectToBroker establishes a connection to a broker
func connectToBroker(address string, username string, password string) (*tls.Conn, *stomp.Conn, error) {
	if isSTOMPTLS(address) {
		netConn, err := tls.Dial("tcp", address, &tls.Config{})
		if err != nil {
			return nil, nil, err
		}

		stompConn, err := stomp.Connect(netConn, stomp.ConnOpt.Login(username, password))
		if err != nil {
			defer netConn.Close()
			return nil, nil, err
		}
		return netConn, stompConn, nil
	}

	stompConn, err := stomp.Dial("tcp", address, stomp.ConnOpt.Login(username,password))
	if err != nil {
		return nil, nil, err
	}
	return nil, stompConn, nil
}

and then I consume it with a snippet like this:

	netConn, stompConn, err := connectToBroker(
		PrimarySTOMPAddress,
		Username,
		Password
	if err != nil {
		fmt.Printf("Failed to connect to primary STOMP address: %s\n", err)
		netConn, stompConn, err = connectToBroker(
			SecondarySTOMPAddress,
			Username,
			Password
		if err != nil {
			panic(err)
		}
	}
	if netConn != nil {
		defer netConn.Close()
	}
	if stompConn != nil {
		defer stompConn.Disconnect()
	}

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

No branches or pull requests

3 participants