GithubHelp home page GithubHelp logo

Comments (6)

roblaszczak avatar roblaszczak commented on July 24, 2024

Do you have more details? Do you mean that this flow of reconnecting is not executing properly: https://github.com/ThreeDotsLabs/watermill-amqp/blob/master/pkg/amqp/subscriber.go#L70 ?

from watermill.

duolabmeng6 avatar duolabmeng6 commented on July 24, 2024

I simulated the rabbmitmq outage

Stopped rabbmitmq

But I don't know how to use your package to capture disconnected yics

I want to catch the exception

Reestablishing channels

from watermill.

duolabmeng6 avatar duolabmeng6 commented on July 24, 2024

How should I add

Listen for rabbmitmq disconnect event

from watermill.

duolabmeng6 avatar duolabmeng6 commented on July 24, 2024

I checked all the documents

There's still no way to write it down

Sorry to bother you.

from watermill.

sdeancos avatar sdeancos commented on July 24, 2024

Hi, I have the same problem.

I think that when the connection is lost and reconnection is done the message channel stops receiving them.

For example, in a loop like the one in the example, messages stop being received.

func process(messages <-chan *message.Message) {
	for msg := range messages {
		log.Printf("received message: %s, payload: %s", msg.UUID, string(msg.Payload))

		// we need to Acknowledge that we received and processed the message,
		// otherwise, it will be resent over and over again.
		msg.Ack()
	}
}

I haven't had much time to look at the reconnect implementation but it's probably something related to the code you said (https://github.com/ThreeDotsLabs/watermill-amqp/blob/master/pkg/amqp/subscriber.go#L70)

Any ideas?

Thanks :D

from watermill.

roblaszczak avatar roblaszczak commented on July 24, 2024

Hello @sdeancos @duolabmeng6 I checked locally and with tests (https://github.com/ThreeDotsLabs/watermill-amqp/blob/master/pkg/amqp/pubsub_reconnect_test.go) and it seems that reconnect is working for me properly. Can you provide a bit more details to reproduce it? Thanks!

This is the code that I'm using

package main

import (
	"context"
	"fmt"
	"time"

	"github.com/ThreeDotsLabs/watermill"
	"github.com/ThreeDotsLabs/watermill-amqp/pkg/amqp"
	"github.com/ThreeDotsLabs/watermill/message"
)

func createPubSub() (message.Publisher, message.Subscriber) {
	publisher, err := amqp.NewPublisher(
		amqp.NewDurablePubSubConfig(
			"amqp://guest:guest@localhost:5672",
			nil,
		),
		watermill.NewStdLogger(true, true),
	)
	if err != nil {
		panic(err)
	}

	subscriber, err := amqp.NewSubscriber(
		amqp.NewDurablePubSubConfig(
			"amqp://guest:guest@localhost:5672",
			amqp.GenerateQueueNameTopicNameWithSuffix("test"),
		),
		watermill.NewStdLogger(true, true),
	)
	if err != nil {
		panic(err)
	}

	return publisher, subscriber
}

func main() {
	pub, sub := createPubSub()

	go func() {
		for {
			pub.Publish("foo", message.NewMessage(time.Now().String(), nil))
			time.Sleep(time.Second)
		}
	}()

	msgs, err := sub.Subscribe(context.Background(), "foo")
	if err != nil {
		panic(err)
	}

	for msg := range msgs {
		fmt.Println(msg.UUID)
		msg.Ack()
	}
}

and docker-compose:

version: '3'
services:
  rabbitmq:
    image: rabbitmq:3.7-management
    restart: unless-stopped
    ports:
      - 5672:5672

I'm running the Go code and I'm restarting docker to force re-connect.

from watermill.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.