[BUG] hyperf/nats decode
- Dominant language
- PHP
- Stars
- 6.9k
- Forks
- 1.3k
- Avg merge
- 4h 21m
- Merged PRs (30d)
- 4
Description
Execute the command and paste the result below.
Command: `uname -a && php -v && composer info | grep hyperf && php --ri swoole`
```bash
Darwin DavidMacBook 22.2.0 Darwin Kernel Version 22.2.0: Tue Nov 8 21:14:19 PST 2022; root:xnu-8792.60.55.131.1~1/RELEASE_ARM64_T6000 arm64
PHP 8.1.12 (cli) (built: Oct 30 2022 12:39:49) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.12, Copyright (c) Zend Technologies
with Zend OPcache v8.1.12, Copyright (c), by Zend Technologies
hyperf/async-queue v3.0.0-rc.15 A async queue component for hyperf.
hyperf/cache v3.0.0-rc.17 A cache component for hyperf.
hyperf/code-generator v0.3.3 Code Generator for Hyperf
hyperf/command v3.0.0-rc.13 Command for hyperf
hyperf/config v3.0.0-rc.8 An independent component that provides configuration container.
hyperf/constants v3.0.0-rc.13 A constants component for hyperf.
hyperf/context v3.0.0-rc.13 A coroutine context library.
hyperf/contract v3.0.0-rc.13 The contracts of Hyperf.
hyperf/coordinator v3.0.0-rc.13 Hyperf Coordinator
hyperf/database v3.0.0-rc.13 A flexible database library.
hyperf/db-connection v3.0.0-rc.13 A hyperf db connection handler for hyperf/database.
hyperf/devtool v3.0.0-rc.13 A Devtool for Hyperf.
hyperf/di v3.0.0-rc.16 A DI for Hyperf.
hyperf/dispatcher v3.0.0-rc.8 A HTTP Server for Hyperf.
hyperf/elasticsearch v3.0.0-rc.1 Elasticsearch client for hyperf
hyperf/engine v1.3.4
hyperf/event v3.0.0-rc.12 an event manager that implements PSR-14.
hyperf/exception-handler v3.0.0-rc.13 Exception handler for hyperf
hyperf/framework v3.0.0-rc.13 A coroutine framework that focuses on hyperspeed and flexible, specifically use for build microservices and middlewares.
hyperf/guzzle v3.0.0-rc.13 Swoole coroutine handler for guzzle
hyperf/http-message v3.0.0-rc.13 microservice framework base on swoole
hyperf/http-server v3.0.0-rc.15 A HTTP Server for Hyperf.
hyperf/ide-helper v3.0.0-rc.1 IDE help files for Hyperf.
hyperf/logger v3.0.0-rc.13 A logger component for hyperf.
hyperf/macroable v3.0.0-rc.13 Hyperf Macroable package which come from illuminate/macroable
hyperf/memory v3.0.0-rc.13 An independent component that use to operate and manage memory.
hyperf/model-listener v3.0.0-rc.1 A model listener for Hyperf.
hyperf/nats v3.0.0-rc.13 A nats library for Hyperf.
hyperf/paginator v3.0.0-rc.13 A paginator component for hyperf.
hyperf/pool v3.0.0-rc.13 An independent universal connection pool component.
hyperf/process v3.0.0-rc.13 A process component for hyperf.
hyperf/redis v3.0.0-rc.15 A redis component for hyperf.
hyperf/server v3.0.0-rc.3 A base server library for Hyperf.
hyperf/snowflake v3.0.0-rc.13 A snowflake library
hyperf/testing v3.0.0-rc.13 Testing for hyperf
hyperf/translation v3.0.0-rc.13 An independent translation component, forked by illuminate/translation.
hyperf/utils v3.0.0-rc.16 A tools package that could help developer solved the problem quickly.
hyperf/validation v3.0.0-rc.13 hyperf validation
swoole
Swoole => enabled
Author => Swoole Team
Version => 5.0.1
Built => Nov 7 2022 13:24:22
coroutine => enabled with boost asm context
kqueue => enabled
rwlock => enabled
sockets => enabled
openssl => OpenSSL 1.1.1s 1 Nov 2022
dtls => enabled
http2 => enabled
json => enabled
curl-native => enabled
pcre => enabled
zlib => 1.2.11
mysqlnd => enabled
async_redis => enabled
Directive => Local Value => Master Value
swoole.enable_coroutine => On => On
swoole.enable_library => On => On
swoole.enable_preemptive_scheduler => Off => Off
swoole.display_errors => On => On
swoole.use_shortname => Off => Off
swoole.unixsock_buffer_size => 262144 => 262144
```
### Description:
https://github.com/hyperf/nats/blob/576c7cc194e075efc1904755f4311cddb2c3c621/src/EncodedConnection.php#L71
if `$message->getBody()` return a JSON string
then `$this->encoder->decode($message->getBody())` will retun a array
But Hyperf\Nats\Message::setBody(): Argument #1 ($body) must be of type string
### Steps To Reproduce:
I use python to push the message:
```
import asyncio
import nats
import json
async def run():
nc = await nats.connect("nats://127.0.0.1:4222")
data = json.dumps({"name": "John Doe", "age": 21})
await nc.publish("hyperf", bytes(data, 'utf-8'))
await nc.close()
asyncio.run(run())```
Then I got the wrong msg
Contributor guide
Assessment
This issue has not been assessed yet.