Git Product home page Git Product logo

Comments (4)

michale-developer avatar michale-developer commented on September 23, 2024

then i try other way, the code below, the process block forever:

conn, err := rabbitmq.NewConn("amqp://xxx:[email protected]:5672/")
if err != nil {
return err
}
args := rabbitmq.Table{
"x-delayed-type": "direct",
}
pub, err := rabbitmq.NewPublisher(conn,
rabbitmq.WithPublisherOptionsExchangeKind("x-delayed-message"),
rabbitmq.WithPublisherOptionsExchangeDurable,
rabbitmq.WithPublisherOptionsExchangeName("panda.test.delay"),
rabbitmq.WithPublisherOptionsExchangeArgs(args),
)
defer pub.Close()
if err != nil {
return err
}

confirmRes := make(chan bool, 1)
pub.NotifyPublish(func(p rabbitmq.Confirmation) {
	confirmRes <- p.Ack
	close(confirmRes)
})

err = pub.PublishWithContext(context.Background(), []byte(`{"test":"a"}`), []string{"delay.queue"},
	rabbitmq.WithPublishOptionsContentType("application/json"),
	rabbitmq.WithPublishOptionsPersistentDelivery,
	rabbitmq.WithPublishOptionsExchange("panda.test.delay"),
	rabbitmq.WithPublishOptionsTimestamp(time.Now()),
)
if err != nil {
	return err
}
for k := range confirmRes {
	if !k {
		return errors.New("server confirm fail")
	}
}

i read the code, find pub.NotifyPublish can't ensure execute before pub.PublishWithContext, so block forever ?

from go-rabbitmq.

theclive avatar theclive commented on September 23, 2024

I have the same problem as described in the description of this issue. When I step through the code, I get to "github.com/rabbitmq/amqp091-go", channel.go:1439 which has ch.confirming equal to false which is why the DeferredConfirmation we get is false.

It looks like the code on publish.go:334 never runs, and therefore never sets the channel into Confirm Mode. @michale-developer did you ever solve this problem?

@wagslane please could you assist?

from go-rabbitmq.

theclive avatar theclive commented on September 23, 2024

I have the same problem as described in the description of this issue. When I step through the code, I get to "github.com/rabbitmq/amqp091-go", channel.go:1439 which has ch.confirming equal to false which is why the DeferredConfirmation we get is false.

It looks like the code on publish.go:334 never runs, and therefore never sets the channel into Confirm Mode. @michale-developer did you ever solve this problem?

@wagslane please could you assist?

I found a workaround. This library ONLY sets the channel into Confirm Mode under two conditions:

  1. If it disconnects and needs to be reconnected (publish.go:117)
  2. If a NotifyPublish handler is used. (publish.go:308)
    (because those are the only two times startPublishHandler is called which invokes publisher.chanManager.ConfirmSafe(false))

So, a workaround is to create a blank NotifyPublish handler even if you don't need one. e.g:

publisher.NotifyPublish(func(p rabbitmq.Confirmation) {
	// DO NOTHING! - THIS IS JUST HERE TO MAKE SURE THE CHANNEL IS PUT INTO CONFIRM MODE
})

from go-rabbitmq.

wagslane avatar wagslane commented on September 23, 2024

Fixed in the latest! You should just need to NotifyPublish OR set the publisher to confirm mode

from go-rabbitmq.

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.