Renaming some stuff and starting on ch. 4 rpc example implemented in Go
This commit is contained in:
parent
4c63923238
commit
b0553c1b8d
@ -1,8 +1,9 @@
|
|||||||
REPO_BASE := github.com/meatballhat/box-o-sand/sylvilagus/go
|
REPO_BASE := github.com/meatballhat/box-o-sand/sylvilagus/go
|
||||||
PACKAGES := \
|
PACKAGES := \
|
||||||
$(REPO_BASE)/sylvilagus-conntest \
|
$(REPO_BASE)/sylvilagus-conntest \
|
||||||
$(REPO_BASE)/sylvilagus-chapter02-hello-world-consumer \
|
$(REPO_BASE)/sylvilagus-ch02-hello-world-consumer \
|
||||||
$(REPO_BASE)/sylvilagus-chapter02-hello-world-producer
|
$(REPO_BASE)/sylvilagus-ch02-hello-world-producer \
|
||||||
|
$(REPO_BASE)/sylvilagus-ch04-rpc-server
|
||||||
|
|
||||||
test: build
|
test: build
|
||||||
go test -x -v $(PACKAGES)
|
go test -x -v $(PACKAGES)
|
||||||
|
14
sylvilagus/go/sylvilagus-ch04-rpc-server/main.go
Normal file
14
sylvilagus/go/sylvilagus-ch04-rpc-server/main.go
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
)
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/meatballhat/box-o-sand/sylvilagus/go/sylvilagus"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
log.Println("Would be using AMQP_URI =", sylvilagus.AMQP_URI)
|
||||||
|
log.Println("OH HAI RPC")
|
||||||
|
}
|
@ -2,21 +2,12 @@ package sylvilagus
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
"os"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/streadway/amqp"
|
"github.com/streadway/amqp"
|
||||||
)
|
)
|
||||||
|
|
||||||
var AMQP_URI = os.Getenv("SYLVILAGUS_AMQP_URI")
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
if len(AMQP_URI) < 1 {
|
|
||||||
log.Fatal("SYLVILAGUS_AMQP_URI is not defined!")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func CreateHelloTopology(connection *amqp.Connection) (*amqp.Channel, error) {
|
func CreateHelloTopology(connection *amqp.Connection) (*amqp.Channel, error) {
|
||||||
channel, err := connection.Channel()
|
channel, err := connection.Channel()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
33
sylvilagus/go/sylvilagus/rpc.go
Normal file
33
sylvilagus/go/sylvilagus/rpc.go
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
package sylvilagus
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
)
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/streadway/amqp"
|
||||||
|
)
|
||||||
|
|
||||||
|
func CreateRPCTopology(connection *amqp.Connection) (channel *amqp.Channel, err error) {
|
||||||
|
if channel, err = connection.Channel(); err != nil {
|
||||||
|
log.Println("Failed to get channel!: ", err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = channel.ExchangeDeclare("rpc", "direct", true, false, false, false, nil); err != nil {
|
||||||
|
log.Println("Failed to declare exchange!: ", err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err = channel.QueueDeclare("ping", false, false, false, false, nil); err != nil {
|
||||||
|
log.Println("Failed to declare queue!: ", err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = channel.QueueBind("ping", "ping", "rpc", false, nil); err != nil {
|
||||||
|
log.Println("Failed to bind to queue!: ", err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return channel, nil
|
||||||
|
}
|
14
sylvilagus/go/sylvilagus/uri.go
Normal file
14
sylvilagus/go/sylvilagus/uri.go
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
package sylvilagus
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
var AMQP_URI = os.Getenv("SYLVILAGUS_AMQP_URI")
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
if len(AMQP_URI) < 1 {
|
||||||
|
log.Fatal("SYLVILAGUS_AMQP_URI is not defined!")
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user