Created
June 26, 2013 17:05
-
-
Save develop7/5869267 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"github.com/streadway/amqp" | |
"log" | |
) | |
func main() { | |
produce() | |
} | |
var ( | |
conn amqp.Connection | |
channel amqp.Channel | |
queue amqp.Queue | |
) | |
const ( | |
queue_name = "asdfasdfasdf" | |
exchange_name = "dawfeasdfawefasd" | |
) | |
func produce() { | |
conn, err := amqp.Dial("amqp://guest:guest@localhost:5672/") | |
if err != nil { | |
log.Fatalf("Connection.open: %s", err) | |
} | |
log.Printf("Got connection %s \n", conn) | |
channel, err := conn.Channel() | |
if err != nil { | |
log.Fatalf("channel.open: %s", err) | |
} | |
log.Printf("Got channel %s \n", channel) | |
err = channel.ExchangeDeclare(exchange_name, "direct", true, false, false, false, nil) | |
if err != nil { | |
log.Fatalf("ExchangeDeclare: %s", err) | |
} | |
err = publish([]byte("foooooooooobarararar")) | |
if err != nil { | |
log.Fatalf("Error publishing msg: %s", err) | |
} | |
} | |
func publish(body []byte) error { | |
msg := amqp.Publishing{ | |
Headers: amqp.Table{}, | |
ContentType: "text/plain", | |
ContentEncoding: "", | |
Body: body, | |
DeliveryMode: amqp.Persistent, | |
Priority: 0, | |
} | |
err := channel.Publish( | |
exchange_name, // publish to default exchange | |
queue_name, // routing to 0 or more queues | |
false, // mandatory | |
false, // immediate | |
msg) | |
if err != nil { | |
return fmt.Errorf("Exchange Publish: %s", err) | |
} | |
return nil | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2013/06/26 20:01:33 Got connection &{{{%!s(int32=0) %!s(uint32=0)} %!s(uint32=0)} {%!s(int32=0) %!s(uint32=0)} {%!s(int32=0) %!s(uint32=0)} %!s(*net.TCPConn=&{{0xc2000a6000}}) %!s(chan amqp.message=0xc2000d0060) %!s(*amqp.writer=&{0xc20008a400}) %!s(chan time.Time=0xc2000d00c0) {{{%!s(int32=0) %!s(uint32=0)} %!s(uint32=0) %!s(uint32=0) %!s(int32=0) %!s(int32=0)} map[] %!s(uint16=0)} %!s(bool=false) [%!s(chan *amqp.Error=0xc2000d03c0)] %!s(chan *amqp.Error=0xc2000d0120) {[%!s(*amqp.PlainAuth=&{guest guest})] / %!s(int=0) %!s(int=131072) 10s} %!s(int=0) %!s(int=9) map[capabilities:map[publisher_confirms:%!s(bool=true) exchange_exchange_bindings:%!s(bool=true) basic.nack:%!s(bool=true) consumer_cancel_notify:%!s(bool=true)] copyright:Copyright (C) 2007-2013 VMware, Inc. information:Licensed under the MPL. See http://www.rabbitmq.com/ platform:Erlang/OTP product:RabbitMQ version:3.0.4]} | |
2013/06/26 20:01:33 Got channel &{{{%!s(int32=0) %!s(uint32=0)} %!s(uint32=0)} {%!s(int32=0) %!s(uint32=0)} {%!s(int32=0) %!s(uint32=0)} %!s(*amqp.Connection=&{{{0 0} 0} {0 0} {0 0} 0xc2000000a0 0xc2000d0060 0xc20006e490 0xc2000d00c0 {{{0 0} 0 0 0 0} map[1:0xc2000aa500] 1} false [0xc2000d03c0] 0xc2000d0120 {[0xc2000a52c0] / 0 131072 10000000000} 0 9 map[capabilities:map[publisher_confirms:true exchange_exchange_bindings:true basic.nack:true consumer_cancel_notify:true] copyright:Copyright (C) 2007-2013 VMware, Inc. information:Licensed under the MPL. See http://www.rabbitmq.com/ platform:Erlang/OTP product:RabbitMQ version:3.0.4]}) %!s(chan amqp.message=0xc2000d0660) {{%!s(int32=0) %!s(uint32=0)} map[]} %!s(uint16=1) %!s(bool=false) [] [] [] [] [] [] %!s(uint64=0) %!s(chan *amqp.Error=0xc2000d06c0) %!s(func(*amqp.Channel, amqp.frame) error=0x435520) %!s(func(*amqp.Channel, amqp.message) error=0x434890) <nil> %!s(*amqp.headerFrame=<nil>) } | |
panic: runtime error: invalid memory address or nil pointer dereference | |
[signal 0xb code=0x1 addr=0x0 pc=0x4388a9] | |
goroutine 1 [running]: | |
github.com/streadway/amqp.(*Channel).Publish(0x71bc60, 0x60d7d0, 0x10, 0x5fde90, 0xc, ...) | |
/home/develop7/src/gostuff/src/github.com/streadway/amqp/channel.go:1206 +0x229 | |
main.publish(0xc2000a5620, 0x14, 0x14, 0x5f2e20, 0x6, ...) | |
/home/develop7/projects/src/fooooo.go:64 +0xf8 | |
main.produce() | |
/home/develop7/projects/src/fooooo.go:44 +0x44f | |
main.main() | |
/home/develop7/projects/src/fooooo.go:10 +0x18 | |
goroutine 2 [syscall]: | |
goroutine 6 [IO wait]: | |
net.runtime_pollWait(0x7f7018bedf00, 0x72, 0x0) | |
/usr/local/go/src/pkg/runtime/znetpoll_linux_amd64.c:118 +0x82 | |
net.(*pollDesc).WaitRead(0xc2000a6080, 0xb, 0xc200091570) | |
/usr/local/go/src/pkg/net/fd_poll_runtime.go:75 +0x31 | |
net.(*netFD).Read(0xc2000a6000, 0xc2000d3000, 0x1000, 0x1000, 0x0, ...) | |
/usr/local/go/src/pkg/net/fd_unix.go:195 +0x2b3 | |
net.(*conn).Read(0xc2000000a0, 0xc2000d3000, 0x1000, 0x1000, 0x0, ...) | |
/usr/local/go/src/pkg/net/net.go:123 +0xc3 | |
bufio.(*Reader).fill(0xc2000d0180) | |
/usr/local/go/src/pkg/bufio/bufio.go:79 +0x10c | |
bufio.(*Reader).Read(0xc2000d0180, 0xc2000005d0, 0x7, 0x7, 0x7, ...) | |
/usr/local/go/src/pkg/bufio/bufio.go:147 +0x1b0 | |
io.ReadAtLeast(0xc200091750, 0xc2000d0180, 0xc2000005d0, 0x7, 0x7, ...) | |
/usr/local/go/src/pkg/io/io.go:284 +0xf7 | |
io.ReadFull(0xc200091750, 0xc2000d0180, 0xc2000005d0, 0x7, 0x7, ...) | |
/usr/local/go/src/pkg/io/io.go:302 +0x6f | |
github.com/streadway/amqp.(*reader).ReadFrame(0xc20006e4a0, 0x0, 0x0, 0x0, 0x0, ...) | |
/home/develop7/src/gostuff/src/github.com/streadway/amqp/read.go:48 +0xb8 | |
github.com/streadway/amqp.(*Connection).reader(0xc2000d2000) | |
/home/develop7/src/gostuff/src/github.com/streadway/amqp/connection.go:346 +0xa5 | |
created by github.com/streadway/amqp.Open | |
/home/develop7/src/gostuff/src/github.com/streadway/amqp/connection.go:153 +0x192 | |
goroutine 7 [select]: | |
github.com/streadway/amqp.(*Connection).heartbeater(0xc2000d2000, 0x2540be400, 0xc2000d03c0) | |
/home/develop7/src/gostuff/src/github.com/streadway/amqp/connection.go:373 +0x234 | |
created by github.com/streadway/amqp.(*Connection).openTune | |
/home/develop7/src/gostuff/src/github.com/streadway/amqp/connection.go:529 +0x34f |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment