Ejemplo n.º 1
8
// HandleMessage handles the Openchain messages for the Peer.
func (d *handler) HandleMessage(msg *pb.Event) error {
	//producerLogger.Debug("Handling Event")
	switch msg.Event.(type) {
	case *pb.Event_Register:
		eventsObj := msg.GetRegister()
		if err := d.register(eventsObj.Events); err != nil {
			return fmt.Errorf("Could not register events %s", err)
		}
	case *pb.Event_Unregister:
		eventsObj := msg.GetUnregister()
		if err := d.deregister(eventsObj.Events); err != nil {
			return fmt.Errorf("Could not unregister events %s", err)
		}
	case nil:
	default:
		return fmt.Errorf("Invalide type from client %T", msg.Event)
	}
	//TODO return supported events.. for now just return the received msg
	if err := d.ChatStream.Send(msg); err != nil {
		return fmt.Errorf("Error sending response to %v:  %s", msg, err)
	}

	return nil
}
Ejemplo n.º 2
0
// HandleMessage handles the Openchain messages for the Peer.
func (d *handler) HandleMessage(msg *pb.Event) error {
	producerLogger.Debug("Handling Event")
	eventsObj := msg.GetRegister()
	if eventsObj == nil {
		return fmt.Errorf("Invalid object from consumer %v", msg.GetEvent())
	}

	if err := d.register(eventsObj.Events); err != nil {
		return fmt.Errorf("Could not register events %s", err)
	}

	//TODO return supported events.. for now just return the received msg
	if err := d.ChatStream.Send(msg); err != nil {
		return fmt.Errorf("Error sending response to %v:  %s", msg, err)
	}

	d.registered = true

	return nil
}