Skip to content

Commit 17f1538

Browse files
committed
2 parents a1e8cc9 + 1c95126 commit 17f1538

File tree

9 files changed

+81
-52
lines changed

9 files changed

+81
-52
lines changed

README.md

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
## Todo
2-
React Native 0.40 fix
3-
4-
52

63
## Installation
74

@@ -11,17 +8,18 @@ npm install react-native-rabbitmq --save
118

129
Installation with CocoaPods
1310

14-
1. In the podfile uncommend "use_frameworks":
11+
1. In the Podfile uncomment "use_frameworks":
1512

1613
```
1714
use_frameworks!
1815
```
1916
2. Add the following to your Podfile, use master because needed fix is not a tag:
2017

2118
```
19+
pod 'react-native-rabbitmq', :path => '../node_modules/react-native-rabbitmq'
2220
pod 'RMQClient', :git => 'https://github.com/rabbitmq/rabbitmq-objc-client.git'
2321
```
24-
3. Instal the cocapods:
22+
3. Install the cocapods:
2523

2624
```
2725
pod install
@@ -73,7 +71,7 @@ to
7371
react-native link
7472

7573

76-
## Android
74+
## Android
7775

7876
npm install react-native-rabbitmq --save
7977

@@ -82,11 +80,13 @@ react-native link
8280

8381
## Usage
8482
```
83+
import { Connection, Exchange, Queue } from 'react-native-rabbitmq';
84+
8585
const config = {
86-
host:'',
87-
port:5672,
88-
username:'user',
89-
password:'password',
86+
host:'',
87+
port:5672,
88+
username:'user',
89+
password:'password',
9090
virtualhost:'vhost'
9191
}
9292
@@ -99,28 +99,28 @@ connection.on('error', (event) => {
9999
connection.on('connected', (event) => {
100100
101101
let queue = new Queue( this.connection, {
102-
name: 'queue_name',
102+
name: 'queue_name',
103103
passive: false,
104-
durable: true,
104+
durable: true,
105105
exclusive: false,
106106
consumer_arguments: {'x-priority': 1}
107107
});
108108
109109
let exchange = new Exchange(connection, {
110-
name: 'exchange_name',
111-
type: 'direct',
112-
durable: true,
110+
name: 'exchange_name',
111+
type: 'direct',
112+
durable: true,
113113
autoDelete: false,
114114
internal: false
115115
});
116116
117117
queue.bind(exchange, 'queue_name');
118-
118+
119119
// Receive one message when it arrives
120120
queue.on('message', (data) => {
121121
122122
});
123-
123+
124124
// Receive all messages send with in a second
125125
queue.on('messages', (data) => {
126126
@@ -136,4 +136,3 @@ let properties = {
136136
exchange.publish(data, routing_key, properties)
137137
138138
```
139-

index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { Platform } from "react-native"
2+
import RNRabbitMqIos from "./index.ios.js"
3+
import RNRabbitMqAndroid from "./index.android.js"
4+
5+
const RNRabbitMq = Platform.OS === "ios" ? RNRabbitMqIos : RNRabbitMqAndroid
6+
7+
export default RNRabbitMq

ios/RCTReactNativeRabbitMq/RCTReactNativeRabbitMq.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#ifdef OLDER_IMPORT
55
#import "RCTBridge.h"
66
#else
7-
#import <React/RCTBridge.h>
7+
#import <React/RCTBridgeModule.h>
88
#endif
99

1010
@interface ReactNativeRabbitMq : NSObject <RCTBridgeModule>

ios/RCTReactNativeRabbitMq/RabbitMqConnection.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#import "RCTBridge.h"
44
#import "RCTEventDispatcher.h"
55
#else
6-
#import <React/RCTBridge.h>
6+
#import <React/RCTBridgeModule.h>
77
#import <React/RCTEventDispatcher.h>
88
#endif
99

@@ -14,4 +14,4 @@
1414

1515
@interface RabbitMqConnection : NSObject <RCTBridgeModule>
1616

17-
@end
17+
@end

ios/RCTReactNativeRabbitMq/RabbitMqDelegateLogger.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#import "RCTBridge.h"
44
#import "RCTEventDispatcher.h"
55
#else
6-
#import <React/RCTBridge.h>
6+
#import <React/RCTBridgeModule.h>
77
#import <React/RCTEventDispatcher.h>
88
#endif
99

@@ -13,4 +13,4 @@
1313

1414
- (nonnull id) initWithBridge:(nonnull RCTBridge *)bridge;
1515

16-
@end
16+
@end

ios/RCTReactNativeRabbitMq/RabbitMqQueue.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@
33
#import "RCTBridge.h"
44
#import "RCTEventDispatcher.h"
55
#else
6-
#import <React/RCTBridge.h>
6+
#import <React/RCTBridgeModule.h>
77
#import <React/RCTEventDispatcher.h>
88
#endif
99

1010
#import <RMQClient/RMQClient.h>
1111

1212
@interface RabbitMqQueue : NSObject <RCTBridgeModule>
1313

14-
- (nonnull id) initWithConfig:(nonnull NSDictionary *)config
14+
- (nonnull id) initWithConfig:(nonnull NSDictionary *)config
1515
channel:(nonnull id<RMQChannel>)channel
1616
bridge:(nonnull RCTBridge *)bridge;
1717

1818
- (void) bind:(nonnull RMQExchange *)exchange routing_key:(NSString *)routing_key;
1919
- (void) unbind:(nonnull RMQExchange *)exchange routing_key:(NSString *)routing_key;
2020
- (void) delete;
2121
- (void) ack: (NSNumber *)deliveryTag;
22-
@end
22+
@end

lib/Exchange.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ import { DeviceEventEmitter } from 'react-native';
22

33
export class Exchange {
44

5-
constructor(connection, exchange_condig) {
5+
constructor(connection, exchange_config) {
66

77
this.callbacks = {};
88
this.rabbitmqconnection = connection.rabbitmqconnection;
99

10-
this.name = exchange_condig.name;
11-
this.exchange_condig = exchange_condig;
10+
this.name = exchange_config.name;
11+
this.exchange_config = exchange_config;
1212

1313
DeviceEventEmitter.addListener('RabbitMqExchangeEvent', this.handleEvent);
1414

15-
this.rabbitmqconnection.addExchange(exchange_condig);
15+
this.rabbitmqconnection.addExchange(exchange_config);
1616
}
1717

1818
handleEvent = (event) => {
@@ -23,20 +23,20 @@ export class Exchange {
2323

2424
on(event, callback){
2525
this.callbacks[event] = callback;
26-
}
27-
26+
}
27+
2828
removeon(event){
2929
delete this.callbacks[event];
30-
}
30+
}
3131

3232
publish(message, routing_key = '', properties = {}){
33-
this.rabbitmqconnection.publishToExchange(message, this.name, routing_key, properties);
33+
this.rabbitmqconnection.publishToExchange(message, this.name, routing_key, properties);
3434
}
3535

3636
delete(){
37-
this.rabbitmqconnection.deleteExchange(this.name);
37+
this.rabbitmqconnection.deleteExchange(this.name);
3838
}
3939

4040
}
4141

42-
export default Exchange;
42+
export default Exchange;

lib/Queue.js

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,23 @@ import {DeviceEventEmitter} from 'react-native';
22

33
export class Queue {
44

5-
constructor(connection, queue_condig, args) {
5+
constructor(connection, queue_config, args) {
66

77
this.callbacks = {};
88
this.rabbitmqconnection = connection.rabbitmqconnection;
99

10-
this.name = queue_condig.name;
11-
this.queue_condig = queue_condig;
10+
this.name = queue_config.name;
11+
this.queue_config = queue_config;
1212
this.arguments = args || {};
1313

1414
this.message_buffer = [];
15-
this.message_buffer_delay = (queue_condig.buffer_delay ? queue_condig.buffer_delay : 1000);
15+
this.message_buffer_delay = (queue_config.buffer_delay ? queue_config.buffer_delay : 1000);
1616
this.message_buffer_timeout = null;
17-
17+
1818
DeviceEventEmitter.addListener('RabbitMqQueueEvent', this.handleEvent);
19-
19+
2020
this.rabbitmqconnection.addQueue(queue_condig, this.arguments);
21+
2122
}
2223

2324
handleEvent = (event) => {
@@ -41,7 +42,7 @@ export class Queue {
4142
clearTimeout(this.message_buffer_timeout);
4243

4344
this.message_buffer_timeout = setTimeout(() => {
44-
45+
4546
if (this.message_buffer.length > 0){
4647
if (this.callbacks.hasOwnProperty('messages')){
4748
this.callbacks['messages'](this.message_buffer);
@@ -60,26 +61,26 @@ export class Queue {
6061

6162
on(event, callback){
6263
this.callbacks[event] = callback;
63-
}
64+
}
6465

6566
removeon(event){
6667
delete this.callbacks[event];
67-
}
68+
}
6869

6970
bind(exchange, routing_key = ''){
70-
this.rabbitmqconnection.bindQueue(exchange.name, this.name, routing_key);
71+
this.rabbitmqconnection.bindQueue(exchange.name, this.name, routing_key);
7172
}
7273

7374
unbind(exchange, routing_key = ''){
74-
this.rabbitmqconnection.unbindQueue(exchange.name, this.name, routing_key);
75+
this.rabbitmqconnection.unbindQueue(exchange.name, this.name, routing_key);
7576
}
7677

7778
delete(){
7879
if (this.name != '') {
79-
this.rabbitmqconnection.removeQueue(this.name);
80-
}
80+
this.rabbitmqconnection.removeQueue(this.name);
81+
}
8182
}
82-
83+
8384
close() {
8485
DeviceEventEmitter.removeListener('RabbitMqQueueEvent', this.handleEvent);
8586
clearTimeout(this.message_buffer_timeout);
@@ -89,9 +90,9 @@ export class Queue {
8990
basicAck(delivery_tag) {
9091

9192
this.rabbitmqconnection.basicAck(this.name, delivery_tag);
92-
93+
9394
}
9495

9596
}
9697

97-
export default Queue;
98+
export default Queue;

react-native-rabbitmq.podspec

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
require 'json'
2+
3+
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
4+
5+
Pod::Spec.new do |s|
6+
s.name = package['name']
7+
s.version = package['version']
8+
s.summary = package['description']
9+
s.description = package['description']
10+
s.license = package['license']
11+
s.author = package['author']
12+
s.homepage = package['homepage']
13+
s.source = { :git => 'https://github.com/rabbitmq/rabbitmq-objc-client.git', :tag => s.version }
14+
15+
s.requires_arc = true
16+
s.platform = :ios, '7.0'
17+
18+
s.preserve_paths = 'README.md', 'package.json', 'index.ios.js'
19+
s.source_files = 'iOS/RCTReactNativeRabbitMq/*.{h,m}'
20+
21+
s.dependency 'React'
22+
end

0 commit comments

Comments
 (0)