Beispiel #1
0
// Start will start the message broker and prepare it for testing.
func (c *Broker) Start(host, port string) (interface{}, error) {
	ctx, err := newContext(c.ProjectID, c.JSONKey)
	if err != nil {
		return "", err
	}

	exists, err := pubsub.TopicExists(ctx, topic)
	if err != nil {
		log.Printf("Failed to check Cloud Pub/Sub topic: %s", err.Error())
		return "", err
	}

	if exists {
		if err := pubsub.DeleteTopic(ctx, topic); err != nil {
			log.Printf("Failed to delete Cloud Pub/Sub topic: %s", err.Error())
			return "", err
		}
	}

	if err := pubsub.CreateTopic(ctx, topic); err != nil {
		log.Printf("Failed to create Cloud Pub/Sub topic: %s", err.Error())
		return "", err
	}

	log.Println("Created Cloud Pub/Sub topic")

	return "", nil
}
Beispiel #2
0
func deleteTopic(ctx context.Context, argv []string) {
	checkArgs(argv, 2)
	topic := argv[1]
	err := pubsub.DeleteTopic(ctx, topic)
	if err != nil {
		log.Fatalf("DeleteTopic failed, %v", err)
	}
	fmt.Printf("Topic %s was deleted.\n", topic)
}
Beispiel #3
0
// Stop will stop the message broker.
func (c *Broker) Stop() (interface{}, error) {
	ctx, err := newContext(c.ProjectID, c.JSONKey)
	if err != nil {
		return "", err
	}

	if err := pubsub.DeleteTopic(ctx, topic); err != nil {
		log.Printf("Failed to delete Cloud Pub/Sub topic: %s", err.Error())
		return "", err
	}

	log.Println("Deleted Cloud Pub/Sub topic")
	return "", err
}