Skip to content

Commit 8aec9d5

Browse files
committed
Add getProperties
1 parent 8f7f0a3 commit 8aec9d5

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

src/Command/PublishCommand.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ protected function configure()
4949
new InputOption('will-retain', null, InputOption::VALUE_OPTIONAL, 'If given, if the client disconnects unexpectedly the message sent out will be treated as a retained message', 0),
5050
new InputOption('ssl', 'S', InputOption::VALUE_OPTIONAL, 'Enable SSL encryption', false),
5151
new InputOption('config-path', null, InputOption::VALUE_OPTIONAL, 'Setting the Swoole config file path'),
52+
new InputOption('properties-path', null, InputOption::VALUE_OPTIONAL, 'Setting the Properties config file path'),
5253
])
5354
);
5455
}

src/Handler/AbstractHandler.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ public function getConnectConfig(): ClientConfig
149149
->setProtocolLevel($this->getProtocolLevel())
150150
->setSockType($this->getSocketType())
151151
->setSwooleConfig($this->getSwooleConfig())
152+
->setProperties($this->getProperties('connect'))
152153
->setMaxAttempts(0); // Disable auto reconnection
153154
}
154155

@@ -184,6 +185,22 @@ public function getSwooleConfig(): array
184185
return [];
185186
}
186187

188+
public function getProperties(string $key = ''): array
189+
{
190+
$path = $this->input->getOption('properties-path');
191+
if ($path && is_file($path)) {
192+
$content = include $path;
193+
194+
if ($key) {
195+
return $content[$key] ?? [];
196+
}
197+
198+
return $content;
199+
}
200+
201+
return [];
202+
}
203+
187204
protected function log($msg): void
188205
{
189206
$date = date('Y-m-d H:i:s');

src/Handler/PublishHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function handle(InputInterface $input, OutputInterface $output): int
4141
if ($this->getConnectConfig()->isMQTT5()) {
4242
$this->logInfo("Connect Reason Code: {$connect['code']}, Reason: " . ReasonCode::getReasonPhrase($connect['code']));
4343
}
44-
$publish = $client->publish($topic, $message, $this->getQos(), $this->getDup(), $this->getRetain());
44+
$publish = $client->publish($topic, $message, $this->getQos(), $this->getDup(), $this->getRetain(), $this->getProperties('publish'));
4545
} catch (\Throwable $e) {
4646
$this->logError('Publish error');
4747
goto failure;

0 commit comments

Comments
 (0)