Пример #1
0
func main() {

	for {
		msgs, err := pubsub.Pull(gcloud.ctx, "syncToFtp", 1)
		if err != nil {
			log.Println(err)
		}
		if len(msgs) > 0 {
			attr := msgs[0].Attributes
			storeID := attr["storeID"]
			orderID := attr["orderID"]

			if err := pubsub.Ack(gcloud.ctx, "syncToFtp", msgs[0].AckID); err != nil {
				log.Println("Ack failed.")
			}

			info, err := initSyncInfo(storeID, orderID)

			if err == nil {
				// fmt.Println("storeID: ", info.storeID)
				// fmt.Println("orderID: ", info.orderID)
				// fmt.Println("gcPrefix: ", info.gcPrefix)
				// fmt.Println("ftpRootPath: ", info.ftpRootPath)
				objects := queryStorageObjects(info)

				uploadObjects(info, objects)
			}
		}
	}
}
Пример #2
0
func (c *Peer) ack() {
	for {
		select {
		case ids := <-c.acks:
			if len(ids) > 0 {
				if err := pubsub.Ack(c.context, c.subscription, ids...); err != nil {
					log.Println("Failed to ack messages")
				}
			}
		case <-c.ackDone:
			return
		}
	}
}
Пример #3
0
func ExamplePull() {
	ctx := Example_auth()

	// E.g. c.CreateSub("sub1", "topic1", time.Duration(0), "")
	msgs, err := pubsub.Pull(ctx, "sub1", 1)
	if err != nil {
		log.Fatal(err)
	}
	log.Printf("New message arrived: %v\n", msgs[0])
	if err := pubsub.Ack(ctx, "sub1", msgs[0].AckID); err != nil {
		log.Fatal(err)
	}
	log.Println("Acknowledged message")
}
Пример #4
0
func subscribe() {
	for {
		// Pull up to 10 messages (maybe fewer) from the subscription.
		// Blocks for an indeterminate amount of time.
		msgs, err := pubsub.PullWait(pubSubCtx, subName, 10)
		if err != nil {
			log.Fatalf("could not pull: %v", err)
		}

		for _, m := range msgs {
			msg := m

			var id int64
			if err := json.Unmarshal(msg.Data, &id); err != nil {
				log.Printf("could not decode message data: %#v", msg)
				go pubsub.Ack(pubSubCtx, subName, msg.AckID)
				continue
			}

			log.Printf("[ID %d] Processing.", id)
			go func() {
				if err := update(id); err != nil {
					log.Printf("[ID %d] could not update: %v", id, err)
					return
				}

				countMu.Lock()
				count++
				countMu.Unlock()

				pubsub.Ack(pubSubCtx, subName, msg.AckID)
				log.Printf("[ID %d] ACK", id)
			}()
		}
	}
}
Пример #5
0
func ExamplePull() {
	ctx := Example_auth()

	msgs, err := pubsub.Pull(ctx, "sub1", 1)
	if err != nil {
		log.Fatal(err)
	}
	log.Printf("New message arrived: %v\n", msgs[0])

	if err := pubsub.Ack(ctx, "sub1", msgs[0].AckID); err != nil {
		log.Fatal(err)
	}
	log.Println("Acknowledged message")

	demo := ClearBladeInfo{}

	demo.authenticateUser()
}
Пример #6
0
func consumePubSubMsgs(projectId string, topicName string) <-chan []byte {
	msgC := make(chan []byte, 100)
	subName := topicName + "-2loggly"
	ackDeadline := time.Second * 20

	client, err := google.DefaultClient(context.Background(), pubsub.ScopePubSub)
	if err != nil {
		logFatal(LogData{
			"event": "pubsub.error.auth",
			"error": err.Error(),
		})
	}
	ctx := cloud.NewContext(projectId, client)

	isSub, err := pubsub.SubExists(ctx, subName)
	if err != nil {
		logFatal(LogData{
			"event": "pubsub.error.subexists",
			"error": err.Error(),
		})
	}
	if !isSub {
		err = pubsub.CreateSub(ctx, subName, topicName, ackDeadline, "")
		if err != nil {
			logFatal(LogData{
				"event": "pubsub.error.createsub",
				"error": err.Error(),
			})
		}
	}

	go func() {
		var lastAckErr error
		var lastDecodeErr error

		for {
			msgs, err := pubsub.PullWait(ctx, subName, 20)
			if err != nil {
				logInfo(LogData{
					"event": "pubsub.error.pull",
					"error": err.Error(),
				})
				time.Sleep(time.Second)
				continue
			}

			lastAckErr = nil
			lastDecodeErr = nil

			for _, m := range msgs {
				jsonBytes, err := msgToLogJson(m.Data)
				if err != nil {
					lastDecodeErr = err
				} else {
					msgC <- jsonBytes
				}

				err = pubsub.Ack(ctx, subName, m.AckID)
				if err != nil {
					lastAckErr = err
				}
			}

			// protect against flood of logs from this application
			// when acks/decodes fail but adding rollup & sleep delay
			if lastAckErr != nil {
				logInfo(LogData{
					"event": "pubsub.error.ack",
					"error": lastAckErr.Error(),
				})
				time.Sleep(time.Second)
			}
			if lastDecodeErr != nil {
				logInfo(LogData{
					"event": "pubsub.error.decode",
					"error": lastDecodeErr.Error(),
				})
				time.Sleep(time.Second)
			}
		}
	}()

	return msgC
}
Пример #7
0
func (s *pubSubServiceImpl) Ack(sub string, ackIDs []string) error {
	return pubsub.Ack(s.ctx, sub, ackIDs...)
}
Пример #8
0
func ack(ctx context.Context, sub string, ackID ...string) {
	err := pubsub.Ack(ctx, sub, ackID...)
	if err != nil {
		log.Printf("Ack failed, %v\n", err)
	}
}
func (this *SalesforceOpportunityEvents) Ack(ctx context.Context, ackID string) error {
	ctx = this.context(ctx)
	logger.Infof("Acknowledging SalesforceOpportunity message receipt, ackID=%s, subscription=%s", ackID, this.Subscription)
	return pubsub.Ack(ctx, this.Subscription, ackID)
}