本文整理汇总了Golang中github.com/streadway/amqp.Channel类的典型用法代码示例。如果您正苦于以下问题:Golang Channel类的具体用法?Golang Channel怎么用?Golang Channel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Channel类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: MakeQueue
func MakeQueue(c *amqp.Channel) amqp.Queue {
q, err := c.QueueDeclare("stress-test-exchange", true, false, false, false, nil)
if err != nil {
log.Fatal(err)
}
return q
}
开发者ID:kaustria,项目名称:rabbit-mq-stress-tester,代码行数:7,代码来源:main.go
示例2: sendKeepAlive
// Function to send keep alive message over specified channel
func sendKeepAlive(channel *amqp.Channel, client ClientConfig) error {
// Create a keepalive struct to send to server
body := &KeepAlive{
Name: client.Name,
Address: client.Address,
Subscriptions: client.Subscriptions,
Timestamp: time.Now().Unix(),
}
// Parse the keepalive struct to json
bodyJson, err := json.Marshal(body)
if err != nil {
return err
}
// Create the amqp message to publish
msg := amqp.Publishing{
ContentType: "application/octet-stream",
DeliveryMode: amqp.Persistent,
Priority: 0,
Body: bodyJson,
}
// Publish message to amqp server
if err := channel.Publish("keepalives", "", false, false, msg); err != nil {
return err
}
// Returns nil as error if message was sent successfully
return nil
}
开发者ID:TjiffTjoff,项目名称:go-alive,代码行数:32,代码来源:alive.go
示例3: MakeQueue
func MakeQueue(c *amqp.Channel, queueName string, queueDurability bool) amqp.Queue {
q, err2 := c.QueueDeclare(queueName, queueDurability, false, false, false, nil)
if err2 != nil {
panic(err2)
}
return q
}
开发者ID:MartyMacGyver,项目名称:rabbit-mq-stress-tester,代码行数:7,代码来源:tester.go
示例4: SendEmail
func SendEmail(req *http.Request, mail Email, r render.Render, ch *amqp.Channel) {
msg, _ := json.Marshal(mail)
q, _ := ch.QueueDeclare(
"email", // name
true, // durable
false, // delete when usused
false, // exclusive
false, // no-wait
nil, // arguments
)
err := ch.Publish(
"", // exchange
q.Name, // routing key
false, // mandatory
false, // immediate
amqp.Publishing{
ContentType: "json/plain",
Body: []byte(msg),
})
if err == nil {
r.JSON(http.StatusOK, map[string]interface{}{"Email": mail})
} else {
r.JSON(http.StatusInternalServerError, err)
}
}
开发者ID:haruio,项目名称:haru-golang-helpcenter,代码行数:28,代码来源:EmailController.go
示例5: newPublisher
/*
If ch is nil, a new Connection and Channel will be created, and this publisher
will 'own' the connection. A call to close() will close both channel and connection.
If ch is provided, then this publisher will reuse the channel and
calls to close() will do nothing.
*/
func newPublisher(serverURI string, cfg *ChannelConfig, ch *amqp.Channel) *Publisher {
var conn *amqp.Connection
var err error
if ch == nil {
conn, err = amqp.Dial(serverURI)
if err != nil {
panic(fmt.Errorf("Failed to connect to RabbitMQ: %v", err))
}
ch, err = conn.Channel()
if err != nil {
panic(fmt.Errorf("Failed to open a channel: %v", err))
}
}
_, err = ch.QueueDeclare(*cfg.Name, *cfg.Durable, *cfg.AutoDelete, *cfg.Exclusive, false, *cfg.Args)
if err != nil {
panic(fmt.Errorf("Failed to declare queue %s: %v", cfg.Name, err))
}
ch.QueuePurge(*cfg.Name, true)
return &Publisher{exch: "", routingKey: *cfg.Name, conn: conn, ch: ch, typeTag: *cfg.TypeTag}
}
开发者ID:robinpercy,项目名称:amqpbeat,代码行数:32,代码来源:amqpbeat_test.go
示例6: handleChange
func handleChange(channel *amqp.Channel, ev *fsnotify.FileEvent) error {
// check to see if the file is locked. If it is then break
path, _ := filepath.Rel(rootDir, ev.Name)
if FileIsLocked(path) {
return nil
}
log.Printf("PUBLISHER: publishing %dB path (%q)", len(path), path)
var change = &Change{
IsCreate: ev.IsCreate(),
IsDelete: ev.IsDelete(),
IsMod: ev.IsModify(),
IsMove: ev.IsRename(),
ModDate: time.Now().UTC(),
Path: path,
Source: hostname,
Checksum: Checksum(ev.Name),
}
msg, err := json.Marshal(change)
if err != nil {
log.Fatalf("ERROR marshaling msg %s", change)
}
if err := channel.Publish(
"changes", // publish to an exchange
"", // routing to 0 or more queues
false, // mandatory
false, // immediate
amqp.Publishing{
Headers: amqp.Table{},
ContentType: "application/json",
ContentEncoding: "",
Body: msg,
DeliveryMode: amqp.Transient, // 1=non-persistent, 2=persistent
Priority: 0, // 0-9
// a bunch of application/implementation-specific fields
/*
ContentType string // MIME content type
ContentEncoding string // MIME content encoding
DeliveryMode uint8 // Transient (0 or 1) or Persistent (2)
Priority uint8 // 0 to 9
CorrelationId string // correlation identifier
ReplyTo string // address to to reply to (ex: RPC)
Expiration string // message expiration spec
MessageId string // message identifier
Timestamp time.Time // message timestamp
Type string // message type name
UserId string // creating user id - ex: "guest"
AppId string // creating application id
*/
},
); err != nil {
log.Fatalf("Exchange Publish: %s", err)
panic(err)
}
return nil
}
开发者ID:blockloop,项目名称:unison,代码行数:60,代码来源:locals.go
示例7: publish
func (rc requestCh) publish() error {
var (
err error
out *amqp.Channel
)
for r := range rc {
if r == nil {
break
}
for out == nil {
out, err = dial()
if err != nil {
out = nil
log.Println(err)
time.Sleep(*backoff)
}
}
err = out.Publish(*exchange, *key, false, false,
amqp.Publishing{
Headers: amqp.Table(r.headers),
DeliveryMode: amqp.Persistent,
Body: []byte(r.body),
},
)
if err != nil {
return err
}
}
return nil
}
开发者ID:presbrey,项目名称:pipe2mq,代码行数:31,代码来源:queue.go
示例8: publish
func (rc RequestChan) publish() error {
var (
err error
out *amqp.Channel
)
for r := range rc {
if r == nil {
break
}
for out == nil {
out, err = dial()
if err != nil {
out = nil
log.Println(err)
time.Sleep(*backoff)
}
}
err = out.Publish(*exchange, *key, false, false,
amqp.Publishing{
Headers: amqp.Table(r.Headers),
ContentType: r.ContentType,
Body: r.Body,
},
)
if err != nil {
return err
}
}
return nil
}
开发者ID:presbrey,项目名称:http2mq,代码行数:31,代码来源:queue.go
示例9: produce
func produce(conn *amqp.Connection, channel *amqp.Channel, val *interface{}) {
if val == nil {
log.Warn("the redis json is nil")
return
}
body, err := json.Marshal(val)
if err != nil || body == nil {
log.Error("redis event to json error: %s , oplog is : %s ", err, string(body))
} else {
routingKey := "redis.event"
log.Info("routing key is : %s ", routingKey)
err = channel.Publish(
EXCHANGE_KEY, // exchange
routingKey, // routing key
false, // mandatory
false, // immediate
amqp.Publishing{
ContentType: "text/plain",
Body: body,
})
if err != nil {
log.Error("publish message err : %s ", err)
}
//TODO recreate channel ?
}
}
开发者ID:hushi55,项目名称:Grep,代码行数:32,代码来源:event.go
示例10: monitoring
func monitoring(uri string, queueName string, mgmtUri string, prefix string) {
var (
queueConn *amqp.Connection
queueChan *amqp.Channel
err error
)
queueConn, queueChan, err = rabbitmqConnect(uri, queueName)
if err != nil {
return
}
for {
log.Printf("fetch rabbitmq stats")
var metrics []graphite.Metric
for _, metric := range fetchQueueMetrics(mgmtUri, prefix) {
metrics = append(metrics, metric)
}
for _, metric := range fetchExchangeMetrics(mgmtUri, prefix) {
metrics = append(metrics, metric)
}
for _, metric := range metrics {
body := []byte(metric.Name + "\t" + metric.Value + "\t" + strconv.FormatInt(metric.Timestamp, 10))
msg := amqp.Publishing{ContentType: "text/plain", Body: body}
err = queueChan.Publish("", queueName, false, false, msg)
if err != nil {
log.Printf("publish err: %s", err)
return
}
//log.Printf("metric\t%s\t\t%s", metric.Name, metric.Value)
}
time.Sleep(time.Second * 5)
}
queueChan.Close()
queueConn.Close()
}
开发者ID:naveenlj,项目名称:rabbitmq-graphite-tool,代码行数:34,代码来源:rabbitmq-graphite-tool.go
示例11: cmdMain
func cmdMain(ch *amqp.Channel) {
fmt.Println(len(os.Args))
if len(os.Args) != 4 {
cmdUsage()
}
name := os.Args[2]
val, _ := strconv.Atoi(os.Args[3])
fmt.Println("ARGS", os.Args, name, val)
m := UpdateMsg{name, val}
msg, err := json.Marshal(m)
if err != nil {
log.Fatal("Barf!", err)
}
err = ch.Publish(
"updateMsgs", // exchange
"", // routing key
false, // mandatory
false, // immediate
amqp.Publishing{
ContentType: "text/json",
Body: msg,
})
failOnError(err, "Failed to publish a message")
log.Printf("Sending msg -- %s", msg)
os.Exit(0)
}
开发者ID:sideb0ard,项目名称:Craxx,代码行数:29,代码来源:cmd.go
示例12: StartSubscribers
func StartSubscribers(amqpChan *amqp.Channel, esClient *elastic.Client, config *config.Config) {
log.Println("Starting RabbitMQ subscribers")
msgChan, err := amqpChan.Consume(config.AmqpQueues[0], "", true, false, false, false, nil)
utils.CheckFatalError(err)
go incomingDocConsumer(msgChan, esClient, config)
log.Println("Started RabbitMQ subscribers")
}
开发者ID:JKolios,项目名称:elasticgin,代码行数:7,代码来源:consumers.go
示例13: MakeQueue
func MakeQueue(c *amqp.Channel) amqp.Queue {
q, err2 := c.QueueDeclare("stress-test-queue", true, false, false, false, nil)
if err2 != nil {
panic(err2)
}
return q
}
开发者ID:dstroot,项目名称:rabbit-mq-stress-tester,代码行数:7,代码来源:amqp.go
示例14: amqpEventReceiver
func amqpEventReceiver(ch *amqp.Channel, q amqp.Queue, c chan Event) {
msgs, err := ch.Consume(
q.Name, // queue
"", // consumer
true, // auto-ack
false, // exclusive
false, // no-local
false, // no-wait
nil, // args
)
if err != nil {
//fixme send error to something ?
}
for d := range msgs {
var ev Event
ev.Headers = d.Headers
ev.Headers["_transport-exchange"] = d.Exchange
ev.Headers["_transport-RoutingKey"] = d.RoutingKey
ev.Headers["_transport-ContentType"] = d.ContentType
ev.Body = d.Body
c <- ev
}
c <- Event{
Body: []byte("dc1?"),
}
os.Exit(1)
}
开发者ID:XANi,项目名称:zerosvc,代码行数:27,代码来源:transport-amqp.go
示例15: main
func main() {
log.Println("Starting elasticgin")
//Config fetch
config := config.GetConfFromJSONFile("config.json")
//ES init
esClient := initESClient(config.ElasticURL, config.Indices, config.SniffCluster)
defer esClient.Stop()
//Rabbitmq init
var amqpChannel *amqp.Channel
if config.UseAMQP {
amqpConnection, amqpChannel := initAMQPClient(config)
defer amqpConnection.Close()
defer amqpChannel.Close()
rabbitmq.StartSubscribers(amqpChannel, esClient, config)
} else {
amqpChannel = nil
}
api := api.SetupAPI(esClient, amqpChannel, config)
api.Run(config.ApiURL)
}
开发者ID:JKolios,项目名称:elasticgin,代码行数:28,代码来源:application.go
示例16: Publish
func (r *Rabbitmq) Publish(ch *amqp.Channel, msg *amqp.Publishing) (err error) {
try_count := 3
if ch == nil {
log.Printf("[WARNING] send to mq failed: Channel must not be empty\n")
return errors.New("ampq channel is nil")
}
defer func() {
if f := recover(); f != nil {
log.Printf("[WARNING] send to mq failed:%v\n", f)
err = f.(error)
}
}()
for i := 0; i < try_count; i++ {
err = ch.Publish(r.Exchange, r.RoutingKey, false, false, *msg)
if err != nil {
conn_err := r.Reconn()
ch1, _ := r.Channel()
*ch = *ch1
log.Printf("[WARNING] RabbitMQ Reconn err is %v send to bnow failed:%v try Count:%v\n", conn_err, err, i)
time.Sleep(time.Second)
continue
}
break
}
return
}
开发者ID:shima-park,项目名称:utils,代码行数:30,代码来源:rabbitmq.go
示例17: run
func (s *Server) run() error {
ch, err := s.dial()
if err != nil {
return err
}
for name, sink := range s.Sinks {
if err := ch.ExchangeDeclare(name, sink.Type, true, false, false, false, nil); err != nil {
return err
}
go func(name string, sink *Sink) {
var (
ch *amqp.Channel
elt []byte
err error
)
for s.alive {
if err != nil {
ch = nil
log.Println(err)
err = nil
time.Sleep(*backoff)
continue
}
if len(elt) == 0 {
elt = <-sink.ch
}
if ch == nil {
if ch, err = s.dial(); err != nil {
continue
}
}
if ch != nil {
err = ch.Publish(name, name, false, false, amqp.Publishing{Body: elt})
if err == nil {
elt = nil
}
}
}
}(name, sink)
}
for i := 0; i < *threads; i++ {
go func() {
for s.alive {
elt := <-s.ch
for _, sink := range s.Sinks {
if sink.regex != nil && !sink.regex.Match(elt) {
continue
}
sink.ch <- elt
}
}
}()
}
go s.consumer()
return nil
}
开发者ID:presbrey,项目名称:mqslice,代码行数:59,代码来源:main.go
示例18: NewDispatcher
func NewDispatcher(jobQueue <-chan amqp.Delivery, worker Worker, replyChannel *amqp.Channel) *Dispatcher {
return &Dispatcher{
jobQueue: jobQueue,
worker: worker,
replyChannel: replyChannel,
confirms: replyChannel.NotifyPublish(make(chan amqp.Confirmation, 1)),
}
}
开发者ID:devTransition,项目名称:job-go-fcgi-proxy,代码行数:8,代码来源:dispatch.go
示例19: QueueBind
func QueueBind(q *amqp.Queue, exchange string, ch *amqp.Channel) error {
return ch.QueueBind(
q.Name, // queue name
"", // routing key
exchange, // exchange
false,
nil)
}
开发者ID:arvindram03,项目名称:asynch-workers,代码行数:8,代码来源:util.go
示例20: Run
/*
Run ...
*/
func (c *Consumer) Run(ch *amqp.Channel) chan []common.MapStr {
events := make(chan []common.MapStr)
// TODO: make exchange part of config
deliveries, err := ch.Consume("test", *c.cfg.Name, false, false, false, false, nil)
utils.FailOnError(err, "Failed to register consumer")
go c.consume(deliveries, events)
return events
}
开发者ID:robinpercy,项目名称:amqpbeat-proto,代码行数:11,代码来源:consumer.go
注:本文中的github.com/streadway/amqp.Channel类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论