|
138 | 138 | } |
139 | 139 | }); |
140 | 140 |
|
| 141 | + $application->add(new Command('dead-letter')) |
| 142 | + ->setDescription('Manage Dead Letter Policies for Pub\Sub') |
| 143 | + ->setHelp(<<<EOF |
| 144 | + The <info>%command.name%</info> command manages Pub\Sub dead letter policies. |
| 145 | +
|
| 146 | + <info>php %command.full_name% create --project my-project |
| 147 | + --topic my-topic |
| 148 | + --subscription my-subscription |
| 149 | + --dead-letter-topic my-dead-letter-topic</info> |
| 150 | +
|
| 151 | + <info>php %command.full_name% update --project my-project |
| 152 | + --topic my-topic |
| 153 | + --subscription my-subscription |
| 154 | + --dead-letter-topic my-dead-letter-topic</info> |
| 155 | +
|
| 156 | + <info>php %command.full_name% remove --project my-project |
| 157 | + --topic my-topic</info> |
| 158 | +
|
| 159 | + <info>php %command.full_name% pull --project my-project |
| 160 | + --topic my-topic --subscription my-subscription</info> |
| 161 | +
|
| 162 | + EOF |
| 163 | + ) |
| 164 | + ->addArgument('action', InputArgument::REQUIRED, 'The action to take') |
| 165 | + ->addOption('project', null, InputOption::VALUE_REQUIRED, 'Your Google Cloud project ID.') |
| 166 | + ->addOption('topic', null, InputOption::VALUE_REQUIRED, 'The topic name.') |
| 167 | + ->addOption('subscription', null, InputOption::VALUE_OPTIONAL, 'The subscription name.') |
| 168 | + ->addOption('dead-letter-topic', null, InputOption::VALUE_OPTIONAL, 'The dead letter topic name.') |
| 169 | + ->addOption('message', null, InputOption::VALUE_OPTIONAL, 'The value of a pubsub message.') |
| 170 | + ->setCode(function ($input, $output) { |
| 171 | + $action = $input->getArgument('action'); |
| 172 | + $projectId = $input->getOption('project'); |
| 173 | + $topicName = $input->getOption('topic'); |
| 174 | + $subscriptionName = $input->getOption('subscription'); |
| 175 | + $deadLetterTopic = $input->getOption('dead-letter-topic'); |
| 176 | + $message = $input->getOption('message'); |
| 177 | + |
| 178 | + switch ($action) { |
| 179 | + case 'create': |
| 180 | + if (!$subscriptionName || !$deadLetterTopic) { |
| 181 | + throw new \RuntimeException( |
| 182 | + 'Subscription Name and Dead Letter Topic are required to create a subscription.' |
| 183 | + ); |
| 184 | + } |
| 185 | + |
| 186 | + dead_letter_create_subscription( |
| 187 | + $projectId, |
| 188 | + $topicName, |
| 189 | + $subscriptionName, |
| 190 | + $deadLetterTopic |
| 191 | + ); |
| 192 | + break; |
| 193 | + |
| 194 | + case 'update': |
| 195 | + if (!$subscriptionName || !$deadLetterTopic) { |
| 196 | + throw new \RuntimeException( |
| 197 | + 'Subscription Name and Dead Letter Topic are required to update a subscription.' |
| 198 | + ); |
| 199 | + } |
| 200 | + |
| 201 | + dead_letter_update_subscription( |
| 202 | + $projectId, |
| 203 | + $topicName, |
| 204 | + $subscriptionName, |
| 205 | + $deadLetterTopic |
| 206 | + ); |
| 207 | + break; |
| 208 | + |
| 209 | + case 'remove': |
| 210 | + if (!$subscriptionName) { |
| 211 | + throw new \RuntimeException( |
| 212 | + 'Subscription Name is required to remove a dead letter policy.' |
| 213 | + ); |
| 214 | + } |
| 215 | + |
| 216 | + dead_letter_remove( |
| 217 | + $projectId, |
| 218 | + $topicName, |
| 219 | + $subscriptionName |
| 220 | + ); |
| 221 | + break; |
| 222 | + |
| 223 | + case 'pull': |
| 224 | + if (!$subscriptionName || !$message) { |
| 225 | + throw new \RuntimeException( |
| 226 | + 'Subscription Name and message is required to pull messages.' |
| 227 | + ); |
| 228 | + } |
| 229 | + |
| 230 | + dead_letter_delivery_attempt( |
| 231 | + $projectId, |
| 232 | + $topicName, |
| 233 | + $subscriptionName, |
| 234 | + $message |
| 235 | + ); |
| 236 | + break; |
| 237 | + |
| 238 | + default: |
| 239 | + throw new \RuntimeException(sprintf('%s is not a valid action', $action)); |
| 240 | + } |
| 241 | + }); |
| 242 | + |
141 | 243 | if (getenv('PHPUNIT_TESTS') === '1') { |
142 | 244 | return $application; |
143 | 245 | } |
|
0 commit comments