npm install --save react-native-amqp
cd ./ios
change in the Podfile line 1:
platform :ios, '9.0' to platform :ios, '11.0'
pod install
npm install --save react-native-amqp
npm install --save react-native-amqp
Installation with CocoaPods
- In the Podfile uncomment "use_frameworks" (Optional):
use_frameworks!
- Add the following to your Podfile, use master because needed fix is not a tag:
pod 'react-native-amqp', :path => '../node_modules/react-native-amqp'
pod 'RMQClient', :git => 'https://github.com/rabbitmq/rabbitmq-objc-client.git'
- Install the cocapods:
pod install
react-native link
npm install --save react-native-amqp
react-native link
import { Connection, Exchange, Queue } from 'react-native-amqp';
const config = {
host:'',
port:5672,
username:'user',
password:'password',
virtualhost:'vhost',
ttl: 10000 // Message time to live,
ssl: true // Enable ssl connection, make sure the port is 5671 or an other ssl port
}
let connection = new Connection(config);
connection.on('error', (event) => {
});
connection.on('connected', (event) => {
let queue = new Queue( this.connection, {
name: 'queue_name',
passive: false,
durable: true,
exclusive: false,
consumer_arguments: {'x-priority': 1}
}, {
// queueDeclare args here like x-message-ttl
});
let exchange = new Exchange(connection, {
name: 'exchange_name',
type: 'direct',
durable: true,
autoDelete: false,
internal: false
});
queue.bind(exchange, 'queue_name');
// Receive one message when it arrives
queue.on('message', (data) => {
});
// Receive all messages send with in a second
queue.on('messages', (data) => {
});
});
let message = 'test';
let routing_key = '';
let properties = {
expiration: 10000
}
exchange.publish(data, routing_key, properties)