Skip to content

Instantly share code, notes, and snippets.

@icambridge
Created February 1, 2017 15:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save icambridge/bd7334304dabc1fac3c6a1441a96a561 to your computer and use it in GitHub Desktop.
Save icambridge/bd7334304dabc1fac3c6a1441a96a561 to your computer and use it in GitHub Desktop.
func main() {
conn, err := amqp.DialConfig("XXXX",
amqp.Config{
Heartbeat: time.Second,
Properties: amqp.Table{
"connection.blocked" : false,
},
})
blockings := conn.NotifyBlocked(make(chan amqp.Blocking))
go func() {
for b := range blockings {
if b.Active {
log.Infof("TCP blocked: %q", b.Reason)
} else {
log.Infof("TCP unblocked")
}
}
}()
if err != nil {
return nil, err
}
ch, err := conn.Channel()
if err != nil {
return nil, err
}
ch.Qos(
30, // prefetch count
0, // prefetch size
false, // global
)
msgs, err := ch.Consume(
"repositories", // queue
"", // consumer
false, // auto-ack
false, // exclusive
false, // no-local
false, // no-wait
nil, // args
)
// messages can be processed
}
<?php
$connection = new \PhpAmqpLib\Connection\AMQPStreamConnection('xxxx', 5672, 'guest', 'guest');
$channel = $connection->channel();
$callback = function($msg) {
echo " [x] Received ", $msg->body, "\n";
sleep(10);
};
$channel->basic_qos(0, 1, false);
$channel->basic_consume('repositories', '', false, false, false, false, $callback);
while(count($channel->callbacks)) {
$channel->wait();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment