GithubHelp home page GithubHelp logo

Comments (5)

duolabmeng6 avatar duolabmeng6 commented on July 24, 2024

rabbitmq

from watermill.

duolabmeng6 avatar duolabmeng6 commented on July 24, 2024
func (p *Publisher) Publish(topic string, messages ...*message.Message) (err error) {
	if p.closed {
		return errors.New("pub/sub is connection closed")
	}
	p.publishingWg.Add(1)
	defer p.publishingWg.Done()

	if !p.IsConnected() {
		return errors.New("not connected to AMQP")
	}

	channel, err := p.amqpConnection.Channel()
	if err != nil {
		return errors.Wrap(err, "cannot open channel")
	}
	defer func() {
		if channelCloseErr := channel.Close(); channelCloseErr != nil {
			err = multierror.Append(err, channelCloseErr)
		}
	}()

How to reuse channel

from watermill.

duolabmeng6 avatar duolabmeng6 commented on July 24, 2024
func (p *Publisher) NewChannel(){
	p.Channel, _ = p.amqpConnection.Channel()
}
func (p *Publisher) Publish2(topic string, messages ...*message.Message) (err error) {
	//if p.closed {
	//	return errors.New("pub/sub is connection closed")
	//}
	//p.publishingWg.Add(1)
	//defer p.publishingWg.Done()
	//
	//if !p.IsConnected() {
	//	return errors.New("not connected to AMQP")
	//}
	//
	//p.channel, err := p.amqpConnection.Channel()
	//if err != nil {
	//	return errors.Wrap(err, "cannot open channel")
	//}
	//defer func() {
	//	if channelCloseErr := channel.Close(); channelCloseErr != nil {
	//		err = multierror.Append(err, channelCloseErr)
	//	}
	//}()

	//if p.config.Publish.Transactional {
	//	if err := p.beginTransaction(channel); err != nil {
	//		return err
	//	}
	//
	//	defer func() {
	//		err = p.commitTransaction(channel, err)
	//	}()
	//}

	//if err := p.preparePublishBindings(topic, channel); err != nil {
	//	return err
	//}

	logFields := make(watermill.LogFields, 3)

	exchangeName := p.config.Exchange.GenerateName(topic)
	logFields["amqp_exchange_name"] = exchangeName

	routingKey := p.config.Publish.GenerateRoutingKey(topic)
	logFields["amqp_routing_key"] = routingKey

	for _, msg := range messages {
		if err := p.publishMessage(exchangeName, routingKey, msg, p.Channel, logFields); err != nil {
			return err
		}
	}

	return nil
}

I try add NewChannel()

Publish2() Just use a channel

now incoming Achieve 13000/s

from watermill.

roblaszczak avatar roblaszczak commented on July 24, 2024

Hello, Publish is implemented without Channel reusing to ensure that all messages are sent after Publish was executed (so in other words if your service will die you are sure that all messages were sent :) ).

If it is fine for you that you may lose some messages in this case - channel can be reused. I think that you can post PR with adding the configuration option for reusing channels if you have some time.

from watermill.

duolabmeng6 avatar duolabmeng6 commented on July 24, 2024

Hello, brother, are you free? Can you help me to add the option of multiplexing channel? Thank you very much

This is very helpful for improving performance

Up to 10000+ / S

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.