Example #1
0
func NewBackend(cfg *AmqpConfig) (v *backend, err error) {
	if cfg == nil {
		cfg = DefaultAmqpConfig()
	}
	v = &backend{
		reporters: dingo.NewHetroRoutines(),
		rids:      make(map[string]map[string]int),
		cfg:       *cfg,
		stores:    dingo.NewHetroRoutines(),
	}

	v.sender, err = newConnection(&v.cfg)
	if err != nil {
		return
	}

	v.receiver, err = newConnection(&v.cfg)
	if err != nil {
		return
	}

	// define exchange
	ci, err := v.sender.Channel()
	if err != nil {
		return
	}
	defer func() {
		if err != nil {
			v.sender.ReleaseChannel(nil)
		} else {
			v.sender.ReleaseChannel(ci)
		}
	}()

	// init exchange
	err = ci.Channel.ExchangeDeclare(
		"dingo.x.result", // name of exchange
		"direct",         // kind
		true,             // durable
		false,            // auto-delete
		false,            // internal
		false,            // noWait
		nil,              // args
	)
	if err != nil {
		return
	}

	return
}
Example #2
0
func NewBackend(cfg *RedisConfig) (v *backend, err error) {
	if cfg == nil {
		cfg = DefaultRedisConfig()
	}
	v = &backend{
		reporters: dingo.NewHetroRoutines(),
		rids:      make(map[string]map[string]int),
		stores:    dingo.NewHetroRoutines(),
		cfg:       *cfg,
	}
	v.pool, err = newRedisPool(&v.cfg)
	if err != nil {
		return
	}

	return
}