Пример #1
0
func Send(ts string, data []byte, settings *yaml.Yaml, senders []string) error {

	debug := settings.Get("debug").(bool)

	var message s.Message
	err := json.Unmarshal(data, &message)
	if err != nil {
		e := fmt.Sprintf("[%s] ERROR Error received: %s\n", ts, err)
		return errors.New(e)
	}

	// Fan out to sends
	var sr s.SendRunner
	var payload s.Payload
	payload.Message = message
	payload.ProcessTime = ts
	payload.Settings = *settings
	var payloads []s.Payload

	payloads = append(payloads, payload)
	in := make([]reflect.Value, len(payloads))

	for i, param := range payloads {
		in[i] = reflect.ValueOf(param)
	}

	for _, send_func := range senders {
		reflect.ValueOf(&sr).MethodByName(send_func).Call(in)
		if debug {
			fmt.Printf("[%s] INFO Message %+v successfully sent to %s.", ts, message, send_func)
		}
	}
	return nil
}
Пример #2
0
func PushCluster(settings *yaml.Yaml, message Message) {
	debug := settings.Get("debug").(bool)
	redis_connection := settings.Get("redis_connection").(string)
	redis_list := settings.Get("redis_list").(string)
	redis_db := settings.Get("redis_db").(int)

	t := time.Now()
	ts := t.Format("Mon Jan 2 15:04:05 -0700 MST 2006")
	rc, err := cluster.NewCluster(redis_connection)
	if err != nil {
		fmt.Printf("[%s] ERROR Error received: %s\n", ts, err)
	}
	if debug {
		fmt.Printf("[%s] INFO Connection made to Redis server %s\n", ts, redis_connection)
	}
	r := rc.Cmd("SELECT", 0)
	if r.Err != nil {
		fmt.Printf("[%s] ERROR Error received: %s\n", ts, r.Err)
	} else {
		if debug {
			fmt.Printf("[%s] INFO Redis database selected: %d\n", ts, redis_db)
		}
	}
	j, errj := json.Marshal(message)
	if errj != nil {
		fmt.Printf("[%s] ERROR Error received: %s\n", ts, errj)
	}
	r = rc.Cmd("LPUSH", redis_list, j)
	rc.Close()
}
Пример #3
0
func PullCluster(settings *yaml.Yaml) (rc *cluster.Cluster) {
	redis_connection := settings.Get("redis_connection").(string)
	rc, err := cluster.NewClusterTimeout(redis_connection, time.Duration(10)*time.Second)
	s.CheckError(err, true)
	return rc
}
Пример #4
0
func PullNode(settings *yaml.Yaml) (rc *redis.Client) {
	redis_connection := settings.Get("redis_connection").(string)
	rc, err := redis.DialTimeout("tcp", redis_connection, time.Duration(10)*time.Second)
	s.CheckError(err, true)
	return rc
}