Ejemplo n.º 1
0
func (rec *Receiver) receiveFromSubscription() {
	for {
		select {
		case msgAndRoute, ok := <-rec.route.C:
			if !ok {
				guble.Debug("messageSouce closed the channel returning from subscription", rec.applicationId)
				return
			}
			if guble.DebugEnabled() {
				guble.Debug("deliver message to applicationId=%v: %v", rec.applicationId, msgAndRoute.Message.MetadataLine())
			}
			if msgAndRoute.Message.Id > rec.lastSendId {
				rec.lastSendId = msgAndRoute.Message.Id
				rec.sendChannel <- msgAndRoute.Message.Bytes()
			} else {
				guble.Debug("dropping message %v, because it was already sent to client", msgAndRoute.Message.Id)
			}
		case <-rec.cancelChannel:
			rec.shouldStop = true
			rec.messageSouce.Unsubscribe(rec.route)
			rec.route = nil
			rec.sendOK(guble.SUCCESS_CANCELED, string(rec.path))
			return
		}

	}
}
Ejemplo n.º 2
0
func (srv *WSHandler) sendLoop() {
	for {
		select {
		case raw := <-srv.sendChannel:
			if guble.DebugEnabled() {
				if len(raw) < 80 {
					guble.Debug("send to client (userId=%v, applicationId=%v, totalSize=%v): %v", srv.userId, srv.applicationId, len(raw), string(raw))
				} else {
					guble.Debug("send to client (userId=%v, applicationId=%v, totalSize=%v): %v...", srv.userId, srv.applicationId, len(raw), string(raw[0:79]))
				}
			}
			if err := srv.clientConn.Send(raw); err != nil {
				guble.Info("applicationId=%v closed the connection", srv.applicationId)
				srv.cleanAndClose()
				break
			}
		}
	}
}