[from now] 2014/11/05 09:37:38

diff --git a/json.go b/json.go
new file mode 100644
index 0000000..985e670
--- /dev/null
+++ b/json.go
@@ -0,0 +1,12 @@
+package main
+
+import "encoding/json"
+
+func ToJson(i interface{}) string {
+	b, err := json.Marshal(i)
+	if err != nil {
+		panic(err)
+	}
+
+	return string(b)
+}
diff --git a/json_test.go b/json_test.go
new file mode 100644
index 0000000..ee65958
--- /dev/null
+++ b/json_test.go
@@ -0,0 +1,20 @@
+package main
+
+import "testing"
+
+func TestToJson(t *testing.T) {
+	var x struct {
+		Name string `json:"name"`
+		Tel  string `json:"tel"`
+	}
+
+	x.Name = "Tom"
+	x.Tel = "012345"
+
+	actual := ToJson(x)
+	expected := `{"name":"Tom","tel":"012345"}`
+
+	if actual != expected {
+		t.Errorf("get %s -> want %s\n", actual, expected)
+	}
+}
diff --git a/main.go b/main.go
index 307182b..41e7f16 100644
--- a/main.go
+++ b/main.go
@@ -5,7 +5,3 @@ import "fmt"
 func main() {
 	fmt.Println("main")
 }
-
-func Sum(v1, v2 int) int {
-	return v1 + v2
-}
diff --git a/main_test.go b/main_test.go
deleted file mode 100644
index 8bcb090..0000000
--- a/main_test.go
+++ /dev/null
@@ -1,11 +0,0 @@
-package main
-
-import "testing"
-
-func TestSum(t *testing.T) {
-	actual := Sum(10, 20)
-	expected := 30
-	if actual != expected {
-		t.Errorf("got %v -> want %v", actual, expected)
-	}
-}
diff --git a/rabbitmq.go b/rabbitmq.go
index 2313ebb..d666945 100644
--- a/rabbitmq.go
+++ b/rabbitmq.go
@@ -1,5 +1,51 @@
 package main

-func Push(message string) bool {
-	return true
+import (
+	"fmt"
+	"log"
+
+	"github.com/streadway/amqp"
+)
+
+func failOnError(err error, msg string) {
+	if err != nil {
+		log.Fatalf("%s: %s", msg, err)
+		panic(fmt.Sprintf("%s: %s", msg, err))
+	}
+}
+
+type Client struct {
+	URL string
+}
+
+func (client *Client) Send(body string) {
+	conn, err := amqp.Dial(client.URL)
+	failOnError(err, "Failed to connect to RabbitMQ")
+	defer conn.Close()
+
+	ch, err := conn.Channel()
+	failOnError(err, "Failed to open a channel")
+	defer ch.Close()
+
+	q, err := ch.QueueDeclare(
+		"hello", // name
+		false,   // durable
+		false,   // delete when usused
+		false,   // exclusive
+		false,   // no-wait
+		nil,     // arguments
+	)
+	failOnError(err, "Failed to declare a queue")
+
+	err = ch.Publish(
+		"",     // exchange
+		q.Name, // routing key
+		false,  // mandatory
+		false,  // immediate
+		amqp.Publishing{
+			ContentType: "text/plain",
+			Body:        []byte(body),
+		},
+	)
+	failOnError(err, "Failed to publish a message")
 }
diff --git a/rabbitmq_test.go b/rabbitmq_test.go
index 70af308..5500791 100644
--- a/rabbitmq_test.go
+++ b/rabbitmq_test.go
@@ -6,16 +6,17 @@ import (
 	"testing"
 )

-func init() {
-	fmt.Println(os.Getenv("WERCKER_RABBITMQ_HOST"))
-	fmt.Println(os.Getenv("WERCKER_RABBITMQ_PORT"))
+var client Client

+func init() {
+	host := os.Getenv("WERCKER_RABBITMQ_HOST")
+	port := os.Getenv("WERCKER_RABBITMQ_PORT")
+	username := os.Getenv("WERCKER_RABBITMQ_USERNAME")
+	password := os.Getenv("WERCKER_RABBITMQ_PASSWORD")
+	url := fmt.Sprintf("amqp://%s:%s@%s:%s/", username, password, host, port)
+	client = Client{url}
 }

-func TestPush(t *testing.T) {
-	actual := Push("message")
-	expected := true
-	if actual != expected {
-		t.Errorf("get %s -> want %s", actual, expected)
-	}
+func TestSend(t *testing.T) {
+	client.Send("hoge")
 }
diff --git a/wercker.yml b/wercker.yml
index 91910a3..c7e27f8 100644
--- a/wercker.yml
+++ b/wercker.yml
@@ -1,6 +1,6 @@
 box: wercker/golang
 services:
-    - wercker/rabbitmq
+  - wercker/rabbitmq
 # Build definition
 build:
   # The steps that will be executed on build
@@ -27,4 +27,4 @@ build:
     - script:
         name: go test
         code: |
-          go test ./...
+          go test -x ./...