• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang protocol.Message类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/smancke/guble/protocol.Message的典型用法代码示例。如果您正苦于以下问题:Golang Message类的具体用法?Golang Message怎么用?Golang Message使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Message类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: setFilters

// 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])
		}
	}
}
开发者ID:smancke,项目名称:guble,代码行数:9,代码来源:rest_message_api.go


示例2: BroadcastMessage

// 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)
}
开发者ID:cosminrentea,项目名称:guble,代码行数:10,代码来源:cluster.go


示例3: parseMessageToMap

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
}
开发者ID:cosminrentea,项目名称:guble,代码行数:13,代码来源:gcm_connector.go


示例4: StoreMessage

// 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
}
开发者ID:smancke,项目名称:guble,代码行数:16,代码来源:dummy_message_store.go


示例5: routeMessage

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)
	}
}
开发者ID:smancke,项目名称:guble,代码行数:22,代码来源:router.go


示例6: HandleMessage

// 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
}
开发者ID:smancke,项目名称:guble,代码行数:41,代码来源:router.go


示例7: StoreMessage

// 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
}
开发者ID:smancke,项目名称:guble,代码行数:43,代码来源:message_store.go



注:本文中的github.com/smancke/guble/protocol.Message类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang testutil.NewMockCtrl函数代码示例发布时间:2022-05-28
下一篇:
Golang protocol.Path函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap