当前操作系统centos8
openjdk version "1.8.0_292"
官网教程https://devdocs.magento.com/guides/v2.4/install-gde/prereq/install-rabbitmq.html
https://www.rabbitmq.com/install-rpm.html
rabbitmq版本更新速度比较快,一定要看erlang对应版本支持,不然会掉坑里
先看erlang对应版本下载对应erlang的rpm版本https://www.rabbitmq.com/which-erlang.html?
rpm -ivh erlang-24.0.4-1.el8.x86_64.rpm --force --nodeps
rpm -q erlang
socat https://pkgs.org/download/socat http://www.rpmfind.net/linux/rpm2html/search.php?query=socat(x86-64)
rabbitmq-server下载安装?https://packagecloud.io/rabbitmq/rabbitmq-server/
rpm -ivh rabbitmq-server-3.8.19-1.el8.noarch.rpm

在magento2中配置rabbitmq?
官网教程https://devdocs.magento.com/guides/v2.4/extension-dev-guide/message-queues/config-mq.html
参考示例:
在 app/etc 的env.php里面加入 queue 的配置
return [
......
'queue' => [
'amqp' => [
'host' => 'localhost',
'port' => '5672',
'user' => 'rabbitmq',
'password' => 'rabbitmq',
'virtualhost' => '/'
]
]
......
]
配置ssl
'queue' =>
array (
'amqp' =>
array (
'host' => 'rabbitmq.example.com',
'port' => '11213',
'user' => 'magento',
'password' => 'magento',
'virtualhost' => '/',
'ssl' => 'true',
'ssl_options' => [
'cafile' => '/etc/pki/tls/certs/DigiCertCA.crt',
'certfile' => '/path/to/magento/app/etc/ssl/test-rabbit.crt',
'keyfile' => '/path/to/magento/app/etc/ssl/test-rabbit.key'
],
),
),
?在<module>/etc/communication.xml创建主题communication.xml 文件
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Communication/etc/communication.xsd">
<topic name="synchronous.rpc.test" request="string" response="string">
<handler name="processRpcRequest" type="Magento\TestModuleSynchronousAmqp\Model\RpcRequestHandler" method="process"/>
</topic>
<topic name="magento.testModuleSynchronousAmqp.api.serviceInterface.execute" schema="Magento\TestModuleSynchronousAmqp\Api\ServiceInterface::execute">
<handler name="processRemoteRequest" type="Magento\TestModuleSynchronousAmqp\Model\RpcRequestHandler" method="process"/>
</topic>
</config>
?说明:这个request就是指定主题的数据类型
queue_consumer.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework-message-queue:etc/consumer.xsd">
<consumer name="basic.consumer" queue="basic.consumer.queue" handler="LoggerClass::log"/>
<consumer name="synchronous.rpc.test" queue="synchronous.rpc.test.queue" handler="LoggerClass::log"/>
<consumer name="rpc.test" queue="queue.for.rpc.test.unused.queue" consumerInstance="Magento\Framework\MessageQueue\BatchConsumer" connection="amqp"/>
<consumer name="test.product.delete" queue="queue.for.test.product.delete" connection="amqp" handler="Magento\Queue\Model\ProductDeleteConsumer::processMessage" maxMessages="200" maxIdleTime="180" sleep="60" onlySpawnWhenMessageAvailable="0"/>
</config>
queue_topology.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework-message-queue:etc/topology.xsd">
<exchange name="magento-topic-based-exchange1" type="topic" connection="db">
<binding id="topicBasedRouting2" topic="anotherTopic" destinationType="queue" destination="topic-queue1">
<arguments>
<!--Not part of our use case, but will be processed if someone specifies them-->
<argument name="argument1" xsi:type="string">value</argument>
</arguments>
</binding>
<arguments>
<argument name="alternate-exchange" xsi:type="string">magento-log-exchange</argument>
</arguments>
</exchange>
<exchange name="magento-topic-based-exchange2" type="topic" connection="db">
<binding id="topicBasedRouting1" topic="#" destinationType="queue" destination="topic-queue2"/>
<arguments>
<argument name="alternate-exchange" xsi:type="string">magento-log-exchange</argument>
</arguments>
</exchange>
</config>
queue_publisher.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework-message-queue:etc/publisher.xsd">
<publisher topic="magento.testModuleSynchronousAmqp.api.serviceInterface.execute" disabled="true" />
<publisher topic="asynchronous.test">
<connection name="amqp" exchange="magento" disabled="false"/>
<connection name="db" exchange="exch1" disabled="true"/>
</publisher>
</config>
|