kegaretail/react-native-rabbitmq

I'm not able to send message to the default exchange

Opened this issue · 0 comments

Hi,
I'm trying to send a message to the lic_requests queue of the default exchange of my RabbitMQ server, my code implementations is as below:

import React, { Component } from 'react';

import { Text, TextInput, View, Button, Alert } from 'react-native';
import DeviceInfo from 'react-native-device-info';
// import { Connection, Exchange, Queue } from 'react-native-amqp';
import { Connection, Exchange, Queue } from 'react-native-rabbitmq';
const config = {
  host: 'localhost',
  port: 5672,
  username: 'mq-pub',   //your rabbitmq management username
  password: 'mq-pub',   //your rabbitmq management password
  virtualhost: '/'
};
class App extends Component {
  constructor() {
    super();
    this.state = {
      customerName: '',
      macAddress: '',
      showName: false,
      uniqueId: ''
    };
    this.getUniqueMacId()
  }
  getUniqueMacId() {
    const uniqueId = DeviceInfo.getUniqueId();
    DeviceInfo.getMacAddress().then((mac) => {
      this.setState({ macAddress: mac, uniqueId: uniqueId })
    });
  }
  displayNameHandler = (e) => {
    let updatedName = e.target.value;
    this.setState({ customerName: updatedName });
  }
  handleSubmit = () => {
    this.setState({
      showName: true
    });
    this.connectionEstablished();
  }
  connectionEstablished = () => {
    let connection = new Connection(config)
    console.log("print", config);
    connection.connect()
    connection.on('error', event => {
      connected = false;
      console.log("you are not connected");
    });
    connection.on('connected', (event) => {
      let queue = new Queue(connection, {
        name: this.state.uniqueId,
        passive: false,
        durable: false,
        exclusive: false,
        consumer_arguments: { 'x-priority': 1 }
      });
      let exchange = new Exchange(connection, {
        name: ''
      });
      queue.bind(exchange, this.state.uniqueId);
      exchange.publish('Hello', 'lic_requests', {});
      queue.on('message', (data) => {
        console.log("Message: ", data);
      });
    });
  }
  render() {
    return (
      <View>
        <View style={{ padding: 70, paddingTop: 200 }}>
          <TextInput
            style={{ height: 40 }}
            placeholder="Enter Your Customer Name"
            value={this.state.customerName}
            onChangeText={(text) => this.setState({ customerName: text })}
          />
        </View>
        <View style={{
          padding: 50
        }}>
          <Button
            title="Press me"
            onPress={() => { this.handleSubmit() }}
            disabled={this.state.customerName == "" ? true : false}
          />
        </View>
        <View>
          <Text style={{ paddingLeft: 50 }}>
            Devide Unique Id : {this.state.uniqueId}
          </Text>
          <Text style={{ paddingLeft: 50 }}>
            Device mac Address : {this.state.macAddress}
          </Text>
          {this.state.showName &&
            <Text style={{ paddingLeft: 50 }}>
              Customer Name : {this.state.customerName}
            </Text>}
        </View>
      </View>
    );
  }
}
export default App;

When I run the above code I don't see any messages in the lic_requests queue, please help me