
Apache Kafka® Connector
Odoo Kafka Connector - Real-Time Data FetchingFeatures
-
Create multiple KafkaConsumer to run concurrently
-
Configured via Master Consumer
-
Sends a return in the form of JSON to the function parameter specified in the Consumer Master
-
Can turn KafkaConsumer on and off with just click of a button
-
Logger is available in the script, so when a failure occurs it can be investigated via log messages
Requirements
-
Install python library:
pip install kafka-python
Compatibility
Odoo Community and Enterprise Editions with kafka-python libraryHow to use:
# Create Master Consumer
The location of the Master Consumer menu is in Settings => Technical => Automation => Kafka Master Consumer [with user group admin]


-
Fill in the mandatory fields correctly, you can click the GET VALUES button to see the return results from Kafka in JSON format which is useful for mapping values.
# Create Method on Your Custom Module

-
Create a function that will be used to receive JSON and perform certain operations. In this example, the function is to create a new PO and SO record from the captured Kafka message. By default, the user used to run this function is SUPERUSER_ID, you can specify the default user in the function to match record rule user access model.
# Done

-
The logger results when odoo receives a message from KafkaConsumer.
# Purchase Request and Sales Quotation Created


-
As a result of executing the function, a new Purchase Request and Sales Quotation record has been created. Make sure the function you create has gone through testing so that no errors occur when Kafka is running.
# Stop KafkaConsumer


-
KafkaConsumer will automatically stop when the odoo service is turned off or restarted, but you can turn it off manually by clicking the STOP button in the Form View or Tree View.
The odoo feature allows users to use KafkaProducer by default, with import from kafka import
KafkaProducer
. So, this module doesn't provide that feature because it's easy to
do.
To send message to Kafka, just do like the following example:
from odoo import models, fields, api from kafka import KafkaProducer from json import dumps
class POInherit(models.Model): _inherit = 'purchase.order'
@api.model def create(self, values): producer = KafkaProducer(bootstrap_servers=['localhost:9092'], value_serializer=lambda x: dumps(x).encode('utf-8')) for x in self: data = { 'partner_id': 1 } producer.send('po-topic', value=data) producer.flush()
return super(POInherit, self).create(values)
Contact us, if you have any questions or technical assistance.
Odoo Proprietary License v1.0 This software and associated files (the "Software") may only be used (executed, modified, executed after modifications) if you have purchased a valid license from the authors, typically via Odoo Apps, or if you have received a written agreement from the authors of the Software (see the COPYRIGHT file). You may develop Odoo modules that use the Software as a library (typically by depending on it, importing it and using its resources), but without copying any source code or material from the Software. You may distribute those modules under the license of your choice, provided that this license is compatible with the terms of the Odoo Proprietary License (For example: LGPL, MIT, or proprietary licenses similar to this one). It is forbidden to publish, distribute, sublicense, or sell copies of the Software or modified copies of the Software. The above copyright notice and this permission notice must be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Please log in to comment on this module