コード例 #1
0
ファイル: rest_message_api.go プロジェクト: smancke/guble
// setFilters sets a field found in the format `filterCamelCaseField` in the
// query of the request to underscore format on the message filters
func (api *RestMessageAPI) setFilters(r *http.Request, msg *protocol.Message) {
	for name, values := range r.URL.Query() {
		if strings.HasPrefix(name, filterPrefix) && len(values) > 0 {
			msg.SetFilter(filterName(name), values[0])
		}
	}
}
コード例 #2
0
ファイル: cluster.go プロジェクト: cosminrentea/guble
// BroadcastMessage broadcasts a guble-protocol-message to all the other nodes in the guble cluster
func (cluster *Cluster) BroadcastMessage(pMessage *protocol.Message) error {
	logger.WithField("message", pMessage).Debug("BroadcastMessage")
	cMessage := &message{
		NodeID: cluster.Config.ID,
		Type:   gubleMessage,
		Body:   pMessage.Bytes(),
	}
	return cluster.broadcastClusterMessage(cMessage)
}
コード例 #3
0
ファイル: gcm_connector.go プロジェクト: cosminrentea/guble
func (conn *GCMConnector) parseMessageToMap(msg *protocol.Message) map[string]interface{} {
	payload := map[string]interface{}{}
	if msg.Body[0] == '{' {
		json.Unmarshal(msg.Body, &payload)
	} else {
		payload["message"] = msg.BodyAsString()
	}
	log.WithFields(log.Fields{
		"module":  "GCM",
		"payload": payload,
	}).Debug("Parsed message is:")
	return payload
}
コード例 #4
0
ファイル: dummy_message_store.go プロジェクト: smancke/guble
// StoreMessage is a part of the `store.MessageStore` implementation.
func (dms *DummyMessageStore) StoreMessage(message *protocol.Message, nodeID uint8) (int, error) {
	partitionName := message.Path.Partition()
	nextID, ts, err := dms.GenerateNextMsgID(partitionName, 0)
	if err != nil {
		return 0, err
	}
	message.ID = nextID
	message.Time = ts
	message.NodeID = nodeID
	data := message.Bytes()
	if err := dms.Store(partitionName, nextID, data); err != nil {
		return 0, err
	}
	return len(data), nil
}
コード例 #5
0
ファイル: router.go プロジェクト: smancke/guble
func (router *router) routeMessage(message *protocol.Message) {
	logger.WithField("msgMetadata", message.Metadata()).Debug("Called routeMessage for data")
	mTotalMessagesRouted.Add(1)

	matched := false
	for path, pathRoutes := range router.routes {
		if matchesTopic(message.Path, path) {
			matched = true
			for _, route := range pathRoutes {
				if err := route.Deliver(message); err == ErrInvalidRoute {
					// Unsubscribe invalid routes
					router.unsubscribe(route)
				}
			}
		}
	}

	if !matched {
		logger.WithField("topic", message.Path).Debug("No route matched.")
		mTotalMessagesNotMatchingTopic.Add(1)
	}
}
コード例 #6
0
ファイル: router.go プロジェクト: smancke/guble
// HandleMessage stores the message in the MessageStore(and gets a new ID for it if the message was created locally)
// and then passes it to the internal channel, and asynchronously to the cluster (if available).
func (router *router) HandleMessage(message *protocol.Message) error {
	logger.WithFields(log.Fields{
		"userID": message.UserID,
		"path":   message.Path}).Debug("HandleMessage")

	mTotalMessagesIncoming.Add(1)
	if err := router.isStopping(); err != nil {
		logger.WithError(err).Error("Router is stopping")
		return err
	}

	if !router.accessManager.IsAllowed(auth.WRITE, message.UserID, message.Path) {
		return &PermissionDeniedError{UserID: message.UserID, AccessType: auth.WRITE, Path: message.Path}
	}

	var nodeID uint8
	if router.cluster != nil {
		nodeID = router.cluster.Config.ID
	}

	mTotalMessagesIncomingBytes.Add(int64(len(message.Bytes())))
	size, err := router.messageStore.StoreMessage(message, nodeID)
	if err != nil {
		logger.WithError(err).Error("Error storing message")
		mTotalMessageStoreErrors.Add(1)
		return err
	}
	mTotalMessagesStoredBytes.Add(int64(size))

	router.handleOverloadedChannel()

	router.handleC <- message

	if router.cluster != nil && message.NodeID == router.cluster.Config.ID {
		go router.cluster.BroadcastMessage(message)
	}

	return nil
}
コード例 #7
0
ファイル: message_store.go プロジェクト: smancke/guble
// StoreMessage is a part of the `store.MessageStore` implementation.
func (fms *FileMessageStore) StoreMessage(message *protocol.Message, nodeID uint8) (int, error) {
	partitionName := message.Path.Partition()

	// If nodeID is zero means we are running in standalone more, otherwise
	// if the message has no nodeID it means it was received by this node
	if nodeID == 0 || message.NodeID == 0 {
		id, ts, err := fms.GenerateNextMsgID(partitionName, nodeID)

		if err != nil {
			logger.WithError(err).Error("Generation of id failed")
			return 0, err
		}

		message.ID = id
		message.Time = ts
		message.NodeID = nodeID

		log.WithFields(log.Fields{
			"generatedID":   id,
			"generatedTime": message.Time,
		}).Debug("Locally generated ID for message")
	}

	data := message.Bytes()

	if err := fms.Store(partitionName, message.ID, message.Bytes()); err != nil {
		logger.
			WithError(err).WithField("partition", partitionName).
			Error("Error storing locally generated  messagein partition")
		return 0, err
	}

	logger.WithFields(log.Fields{
		"id":            message.ID,
		"ts":            message.Time,
		"partition":     partitionName,
		"messageUserID": message.UserID,
		"nodeID":        nodeID,
	}).Debug("Stored message")

	return len(data), nil
}