Example #1
0
func (s *RedismqSuite) SetUpSuite(c *gocheck.C) {
	s.queue = redismq.CreateQueue("localhost", "6379", "", 3, "redismq_tests")
	err := s.queue.Delete()
	c.Assert(err, gocheck.IsNil)
	s.consumer, err = s.queue.AddConsumer("redismq_tests")
	c.Assert(err, gocheck.IsNil)
}
Example #2
0
func (redismqQFactory) get(name, consumerName string) (*redismqQ, error) {
	host, err := config.GetString("redis-queue:host")
	if err != nil {
		host = "localhost"
	}
	port, err := config.GetString("redis-queue:port")
	if err != nil {
		if nport, err := config.GetInt("redis-queue:port"); err != nil {
			port = "6379"
		} else {
			port = fmt.Sprintf("%d", nport)
		}
	}
	password, _ := config.GetString("redis-queue:password")
	db, err := config.GetInt("redis-queue:db")
	if err != nil {
		db = 3
	}
	queue := redismq.CreateQueue(host, port, password, int64(db), name)
	consumer, err := queue.AddConsumer(consumerName)
	if err != nil {
		return nil, err
	}
	return &redismqQ{name: name, queue: queue, consumer: consumer}, nil
}
Example #3
0
func write(queue string) {
	testQueue := redismq.CreateQueue("localhost:6379", "", 9, queue)
	payload := randomString(1024 * 1) //adjust for size
	for {
		testQueue.Put(payload)
	}
}
Example #4
0
File: load.go Project: jbli/redismq
func main() {
	runtime.GOMAXPROCS(5)
	server := redismq.NewServer("localhost", "6379", "", 9, "9999")
	server.Start()
	queue := redismq.CreateQueue("localhost", "6379", "", 9, "example")
	go write(queue)
	go read(queue, "1")
	go read(queue, "2")
	go read(queue, "3")
	select {}
}
func PutMessage(message string) int {
	// mQueue := redismq.CreateQueue(Network, Port, "", 0, queue)
	fmt.Println(Address + ":" + Port)
	SeaechMQ = redismq.CreateQueue(Address, Port, "", 0, "SearchQueue")
	err := SeaechMQ.Put(message)
	if err != nil {
		fmt.Println(err)
		return 1
	}
	return 0
}
Example #6
0
func read(queue, prefix string) {
	testQueue := redismq.CreateQueue("localhost:6379", "", 9, queue)
	consumer, err := testQueue.AddConsumer("testconsumer" + prefix)
	if err != nil {
		panic(err)
	}
	consumer.ResetWorking()
	for {
		p, err := consumer.MultiGet(200)
		if err != nil {
			log.Println(err)
			continue
		}
		p[len(p)-1].MultiAck()
	}
}
Example #7
0
func (ri *RedisMQInput) Init(config interface{}) error {
	ri.conf = config.(*RedisMQInputConfig)
	statInterval := ri.conf.StatInterval
	ri.statInterval = time.Millisecond * time.Duration(statInterval)
	ri.stopChan = make(chan bool)
	var err error
	//ri.rdqueue, err = redismq.SelectQueue(ri.conf.Address, "6379", "", 9, "clicks")
	//if err != nil {
	//        ri.rdqueue = redismq.CreateQueue(ri.conf.Address, "6379", "", 9, "clicks")
	//}
	ri.rdqueue = redismq.CreateQueue(ri.conf.Address, "6379", "", 9, "clicks")
	ri.rdconsumer, err = ri.rdqueue.AddConsumer("testconsumer")
	if err != nil {
		panic(err)
	}
	return nil
}
Example #8
0
func (ro *RedisMQOutput) Init(config interface{}) error {
	ro.conf = config.(*RedisMQOutputConfig)
	//var err error
	//ro.rdqueue, err = redismq.SelectBufferedQueue(ro.conf.Address, "6379", "", 9, "example", 200)
	//ro.rdqueue, err = redismq.SelectQueue(ro.conf.Address, "6379", "", 9, "clicks")
	//if err != nil {
	//server := redismq.NewServer(ro.conf.Address, "6379", "", 9, "9999")
	//server.Start()
	//ro.rdqueue = redismq.CreateBufferedQueue(ro.conf.Address, "6379", "", 9, "example", 200)
	//err := ro.rdqueue.Start()
	//if err != nil {
	//     panic(err)
	//}
	//ro.rdqueue = redismq.CreateQueue(ro.conf.Address, "6379", "", 9, "clicks")
	//}
	ro.rdqueue = redismq.CreateQueue(ro.conf.Address, "6379", "", 9, "clicks")
	return nil
}
Example #9
0
//读取SearchQueue中的队列的数据
func ReadMQ() {
	testQueue := redismq.CreateQueue(RedisAddress, RedisPort, "", 0, "SearchQueue")
	consumer, err := testQueue.AddConsumer("searchconsumer")
	if err != nil {
		panic(err)
	}
	consumer.ResetWorking()
	for {
		p, err := consumer.MultiGet(200)
		if err != nil {
			log.Println(err)
			continue
		}
		for _, v := range p {
			ms := v.Payload
			CreateIndex(ms)
		}
		p[len(p)-1].MultiAck()
	}
}
Example #10
0
func main() {
	testQueue := redismq.CreateQueue("localhost", "6379", "", 9, "clicks")
	for i := 0; i < 10; i++ {
		testQueue.Put("testpayload")
	}
	consumer, err := testQueue.AddConsumer("testconsumer")
	if err != nil {
		panic(err)
	}
	for i := 0; i < 10; i++ {
		p, err := consumer.Get()
		if err != nil {
			fmt.Println(err)
			continue
		}
		fmt.Println(p.CreatedAt)
		err = p.Ack()
		if err != nil {
			fmt.Println(err)
		}
	}
}