Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
krishnmobilehub opened this issue Apr 5, 2021 · 0 comments
Open

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

krishnmobilehub opened this issue Apr 5, 2021 · 0 comments

Comments

@krishnmobilehub
Copy link

krishnmobilehub commented Apr 5, 2021

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

@krishnmobilehub krishnmobilehub changed the title I don't see any messages in the lic_requests queue in rabbitmq I'm not able to send message to the default exchange Apr 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant