Comments (5)
rabbitmq
from watermill.
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.
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.
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.
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)
- How to subscribe to all gochannel ? HOT 2
- Any plans to add support of RabbitMQ Streaming?
- Generated topic names for PubSub tests does not conform with Azure guidelines
- How to delete message after ack? HOT 1
- Context not being propagated through command bus HOT 2
- Is it possible to get google pubsub server generated unique message-id? HOT 3
- Data race on Publish for Google pubsub
- SQLite driver HOT 4
- Log custom fields inside message router
- Invalid publisher name in metrics
- Resume after shutdown always fetch last interrupted message again
- How to process a batch of received messages instead of a single piece?
- Can you output the message metadata to the logs?
- Only post messages after subscribing
- Watermill tests fail on windows
- The publish signature does not allow for a context.Context to be passed HOT 2
- Router closes publisher before message processing is done
- Removing usage of https://github.com/hashicorp/go-multierror
- [watermill-http] Custom HTTP response status HOT 2
- [watermill-kafka] is watermill-kafka still maintained? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from watermill.