Multiresponse for Yii2
ΠΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ Π΄Π»Ρ Π΄ΠΎΠ·Π°Π³ΡΡΠ·ΠΊΠΈ ΠΊΠΎΠ½ΡΠ΅Π½ΡΠ° ΡΠ΅ΡΠ΅Π· websocket. Π£ΡΠΊΠΎΡΡΠ΅Ρ ΠΎΡΡΠΈΡΠΎΠ²ΠΊΡ Π²ΠΈΠ΄ΠΆΠ΅ΡΠΎΠ² ΠΌΠΈΠΊΡΠΎΡΠ΅ΡΠ²ΠΈΡΠΎΠ² Π΄ΠΎ 50% ΠΏΡΡΠ΅ΠΌ ΡΠ°ΡΠΏΠ°ΡΠ°Π»Π»Π΅Π»ΠΈΠ²Π°Π½ΠΈΡ ΠΎΠ±ΡΠ°ΡΠ΅Π½ΠΈΠΉ ΠΊ API. Π’Π°ΠΊ ΠΆΠ΅ ΠΌΠΎΠΆΠ½ΠΎ ΡΠ°ΡΠΏΠ°ΡΠ°Π»Π»Π΅Π»ΠΈΡΡ ΠΈ ΠΎΠ±ΡΠ°Π±ΠΎΡΠΊΡ ΡΠ΅ΡΡΡΡΠΎΠ΅ΠΌΠΊΠΈΡ
Π·Π°Π΄Π°Ρ., (*1)
Installation
The preferred way to install this extension is through composer., (*2)
Either run, (*3)
composer require larsnovikov/yii2multiresponse
or add, (*4)
"larsnovikov/yii2multiresponse": "*"
to the require section of your composer.json
file., (*5)
Usage
- ΠΠΎΠ±Π°Π²Ρ Π² ΠΊΠΎΠ½ΡΠΈΠ³Π΅ Π²
modules
:
'yii2multiresponse' => [
'class' => 'vendor\larsnovikov\yii2multiresponse\Module',
'socketUrls' => [
// TODO ΡΡΡ Π½Π΅ΠΎΠ±Ρ
ΠΎΠ΄ΠΈΠΌΠΎ ΡΠΊΠΎΠ½ΡΠΈΠ³ΡΡΠΈΡΠΎΠ²Π°ΡΡ ΠΏΡΡΠΈ Π΄Π»Ρ Π²ΠΈΠ΄ΠΆΠ΅ΡΠΎΠ² ΠΊ WebSocket ΡΠ΅ΡΠ²Π΅ΡΡ
\vendor\larsnovikov\yii2multiresponse\examples\widgets\HtmlTestWidget::class => [
'ws://socket-test.loc:5005',
'ws://socket-test.loc:5006',
'ws://socket-test.loc:5007'
],
\vendor\larsnovikov\yii2multiresponse\examples\widgets\JsonTestWidget::class => [
'ws://socket-test.loc:5005',
'ws://socket-test.loc:5006',
'ws://socket-test.loc:5007'
]
]
],
- ΠΠΎΠ±Π°Π²Ρ Π² ΠΊΠΎΠ½ΡΠΈΠ³Π΅ Π²
components
ΠΎΡΠ΅ΡΠ΅Π΄Ρ:
'multiResponseQueue' => array_merge(
[
'class' => \yii\queue\amqp_interop\Queue::class,
'queueName' => 'multiresponse.queue'
],
[
'port' => 5672,
'user' => 'public',
'password' => 'public',
'driver' => yii\queue\amqp_interop\Queue::ENQUEUE_AMQP_LIB,
'dsn' => 'amqp://public:public@172.17.0.1:5672/%2F',
]
),
-
ΠΠΎΠ±Π°Π²Ρ Π² ΠΊΠΎΠ½ΡΠΈΠ³Π΅ Π² bootstrap
Π½Π°Π·Π²Π°Π½ΠΈΠ΅ ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½ΡΠ° ΠΎΡΠ΅ΡΠ΅Π΄ΠΈ, (*6)
-
Π£Π½Π°ΡΠ»Π΅Π΄ΡΠΉ ΡΠ²ΠΎΠΉ Π²ΠΈΠ΄ΠΆΠ΅Ρ ΠΎΡ vendor\larsnovikov\yii2multiresponse\widgets\AbstractHtmlWidget
ΠΈΠ»ΠΈ vendor\larsnovikov\yii2multiresponse\widgets\AbstractJsonWidget
Π² Π·Π°Π²ΠΈΡΠΈΠΌΠΎΡΡΠΈ ΠΎΡ ΡΠΎΠ³ΠΎ ΠΊΠ°ΠΊΠΎΠΉ ΠΎΡΠ²Π΅Ρ ΠΎΡ WS-ΡΠ΅ΡΠ²Π΅ΡΠ° Π½Π°Π΄ΠΎ ΠΏΠΎΠ»ΡΡΠΈΡΡ, (*7)
-
ΠΡΠ²Π΅Π΄ΠΈ Π²ΠΈΠ΄ΠΆΠ΅Ρ, Π½Π°ΠΏΡΠΈΠΌΠ΅Ρ:, (*8)
echo \vendor\larsnovikov\yii2multiresponse\examples\widgets\HtmlTestWidget::widget([
'dataRequest' => new \vendor\larsnovikov\yii2multiresponse\requests\DataRequest(
'@vendor/larsnovikov/yii2multiresponse/widgets/views/empty_container',
\vendor\larsnovikov\yii2multiresponse\examples\widgets\HtmlTestWidget::class,
[
'test1' => rand(0, 9999),
'test2' => rand(0, 9999)
])
]);
ΠΠ°ΠΏΡΡΠΊ
- ΠΠ°ΠΏΡΡΡΠΈ WSServer
php yii yii2multiresponse/server/start <port>
ΠΈΠ»ΠΈ bash socket.sh <port>
, Π³Π΄Π΅ <port>
- Π½ΠΎΠΌΠ΅Ρ ΠΏΠΎΡΡΠ°
- ΠΠ°ΠΏΡΡΡΠΈ ΡΠ»ΡΡΠ°ΡΠ΅Π»Π΅ΠΉ ΠΎΡΠ΅ΡΠ΅Π΄Π΅ΠΉ, Π½Π°ΠΏΡΠΈΠΌΠ΅Ρ:
php yii multi-response-queue/listen