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

Router/Req autoreconnect not taking effect? #157

Open
freitzzz opened this issue Oct 17, 2024 · 0 comments
Open

Router/Req autoreconnect not taking effect? #157

freitzzz opened this issue Oct 17, 2024 · 0 comments

Comments

@freitzzz
Copy link

Hey

I'm building a pub/sub server (many-to-one), in which pub clients use REQ sockets and the sub server uses a ROUTER socket, similar to what's happening in this pic:

image

The thing is, sometimes the sub server loses connection in the network and all the pub clients log this error:

zmq4: no connections available)

To make my system fault resilient, I'm looking into including an auto-reconnect feat to pub clients. I notice the library also includes that option, but even after enabling it, pub clients still log the same message. Is it expected? Does auto-reconnect only work in certain architectures like REQ/REP?


Some of my source-code:

// Wraps [zmq4.Socket] so context can be accessed for extracting dependencies.
type Socket struct {
	zmq4.Socket
	ctx context.Context
}


// Creates a new sub [zmq4-Socket] wrapper with a custom context.
// The context must contain all the dependencies required by the socket.
func NewSubSocket(ctx context.Context) Socket {
	return Socket{
		Socket: zmq4.NewRouter(ctx),
		ctx:    ctx,
	}
}

// Creates a new sub [zmq4-Socket] wrapper with a custom context.
// The context must contain all the dependencies required by the socket.
func NewPubSocket(ctx context.Context) Socket {
	return Socket{
		Socket: zmq4.NewReq(ctx, zmq4.WithAutomaticReconnect(true)),
		ctx:    ctx,
	}
}


func (s Socket) PublishAndForget(m msg) {
	logging.LogInfo("publishing msg with topic: %d", m.Topic)

	b, err := encode(m)
	if err != nil {
		log.Printf("failed to encode message, %v\n", err)
	}

	err = s.Send(zmq4.NewMsg(b))
	if err != nil {
		log.Printf("failed to publish message, %v\n", err)
	}
}
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

1 participant