Giter Site home page Giter Site logo

nsqclient's Introduction

nsqclient

nsq client for golang

Build Status codecov Go Report Card
GoDoc

Connection

nsqclient.Connect(map[string]Config{
    "default": Config{
        Host:     "10.64.146.231",
        Port:     "4150",
        InitSize: 10,
        MaxSize:  10,
    },
    "other": Config{
        Host:     "10.64.146.22",
        Port:     "4150",
        InitSize: 10,
        MaxSize:  10,
    },
})

Publish

写入nsq为了方便进行单元测试,可以注入nsqclient.Producer接口,然后在单元测试使用mock的实现

// default client
nsq := nsqclient.NewProducer("default")
nsq.Publish("topic","body")

//mock
nsq := nsqclient.NewMockProducer("default")
nsq.Publish("topic","body")

Consumer

// default connect
consumer := &nsqclient.NsqHandler{
    Topic:   "log",
    Channel: "default",
    Size:   10,
}

consumer.SetHandle(func(lg logger.ILogger, message *nsq.Message) error {
    // something
    return nil
})

nsqclient.Register(consumer, "access_log")

nsqclient.Run("access_log", ctx)

// other connect
consumer := &nsqclient.NsqHandler{
    Connect: "other",
    Topic:   "log",
    Channel: "default",
    Size:   10,
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.