lishelun/nsq 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

lishelun/nsq

最新稳定版本:0.9.1

Composer 安装命令:

composer require lishelun/nsq

包简介

NSQ Client for PHP

README 文档

README

PHP Client for NSQ.

Latest Stable Version Total Downloads License codecov Mutation testing badge telegram

This library follow SemVer. Until version 1.0 will be released anything MAY change at any time, public API SHOULD NOT be considered stable. If you want use it before stable version was released install strict version without range.

Installation

This library is installable via Composer:

composer require nsq/nsq

Requirements

This library requires PHP 8.0 or later.

Although not required, it is recommended that you install the phpinnacle/ext-buffer to speed up phpinnacle/buffer .

Features

  • PUB
  • SUB
  • Feature Negotiation
  • Discovery
  • Backoff
  • TLS
  • Deflate
  • Snappy
  • Sampling
  • AUTH

Usage

Producer

use Nsq\Producer;

$producer = Producer::create(address: 'tcp://nsqd:4150');

// Publish a message to a topic
$producer->publish('topic', 'Simple message');

// Publish multiple messages to a topic (atomically) 
$producer->publish('topic', [
    'Message one',
    'Message two',
]);

// Publish a deferred message to a topic
$producer->publish('topic', 'Deferred message', delay: 5000);

Consumer

use Nsq\Consumer;
use Nsq\Message;

$consumer = Consumer::create(
    address: 'tcp://nsqd:4150', 
    topic: 'topic',
    channel: 'channel',
    onMessage: static function (Message $message): Generator {
        yield $message->touch(); // Reset the timeout for an in-flight message        
        yield $message->requeue(timeout: 5000); // Re-queue a message (indicate failure to process)        
        yield $message->finish(); // Finish a message (indicate successful processing)        
    },
);

Lookup

use Nsq\Lookup;
use Nsq\Message;

$lookup = new Lookup('http://nsqlookupd0:4161');
$lookup = new Lookup(['http://nsqlookupd0:4161', 'http://nsqlookupd1:4161', 'http://nsqlookupd2:4161']);

$callable = static function (Message $message): Generator {
    yield $message->touch(); // Reset the timeout for an in-flight message        
    yield $message->requeue(timeout: 5000); // Re-queue a message (indicate failure to process)        
    yield $message->finish(); // Finish a message (indicate successful processing)        
};

$lookup->subscribe(topic: 'topic', channel: 'channel', onMessage: $callable);  
$lookup->subscribe(topic: 'anotherTopic', channel: 'channel', onMessage: $callable);

$lookup->unsubscribe(topic: 'local', channel: 'channel');
$lookup->stop(); // unsubscribe all  

Integrations

License:

The MIT License (MIT). Please see LICENSE for more information.

统计信息

  • 总下载量: 399
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-12-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固