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

Running in the Windows C++ environment #494

Closed
gunhak01 opened this issue Feb 24, 2023 · 8 comments
Closed

Running in the Windows C++ environment #494

gunhak01 opened this issue Feb 24, 2023 · 8 comments

Comments

@gunhak01
Copy link

Hi, I was given this library to try and utilize rabbitmq in c++.

I use visual studio and received the library via nuget.
But when I tried to run it through tcpchannel, I got a lot of LNK2019, LNK2001 errors.

My question is twofold.

  1. is there anything I need to do besides getting the package from nuget?

  2. do I need to implement the tcp connection part myself in the windows c++ environment? My English is weak and I don't understand much from the readme.

Thanks.

@lukebakken
Copy link

lukebakken commented Feb 25, 2023

https://groups.google.com/g/rabbitmq-users/c/lWcWxbQE4Fc

Please see this example:

https://github.com/CopernicaMarketingSoftware/AMQP-CPP/blob/master/examples/libuv.cpp

LibUV is supported on Windows.

Note: see this related issue #491

@gunhak01
Copy link
Author

gunhak01 commented Mar 2, 2023

@lukebakken I'm trying to create a class that inherits from ConnectionHandler and do tcp communication via libuv, as suggested as a solution in #491. However, I'm not sure about the part where I put the IP address in the connection, do you have any ideas on that?
In onReady, I have the code to queue, exchange and publish the channel.

MyConnectionHandler handler;

AMQP::Login login("admin", "nimda");
AMQP::Connection connection(&handler, login, "10.10.50.242");

handler.onReady(&connection);

@lukebakken
Copy link

lukebakken commented Mar 2, 2023

@gunhak01 the best way to help me (and other people) assist you is to provide a git repository with all of your code that I can clone, compile, and run to see EXACTLY what you are seeing. Please do that. Using GitHub would be ideal. We can then take this discussion to your repository and close this issue.

@gunhak01
Copy link
Author

gunhak01 commented Mar 2, 2023

@lukebakken Thank you for your interest. Right now I can't upload it to GitHub.
But since my code is not very long, I will post it here.
My code is below and I installed amqpcpp and libuv via vcpkg with the latest 64-bit versions (4.3.19 and 1.44.2, respectively).
This is all I have implemented and I would like to try sending at least one message to rabbitmq first via onReady().

#define NOMINMAX
#include <amqpcpp.h>
#include <uv.h>

class MyConnectionHandler : public AMQP::ConnectionHandler
{
private:
  uv_loop_t* loop;
  uv_tcp_t* socket;
  uv_write_t write_req;
  uv_buf_t buffer;

public:
  MyConnectionHandler()
  {
    loop = uv_default_loop();
    socket = new uv_tcp_t();
    uv_tcp_init(loop, socket);
  }

  virtual void onData(AMQP::Connection* connection, const char* data, size_t size)
  {
    buffer = uv_buf_init(const_cast<char*>(data), size);
    uv_write(&write_req, reinterpret_cast<uv_stream_t*>(socket), &buffer, 1,
             [](uv_write_t* req, int status) {
      // Check the status and handle any errors
      // ...
    });
  }

  void onReady(AMQP::Connection* connection) override
  {
    std::cout << "Connected to RabbitMQ!" << std::endl;

    // create a channel
    AMQP::Channel channel(connection);

    // declare an exchange
    channel.declareExchange("my-exchange", AMQP::fanout);

    // declare a queue
    channel.declareQueue("my-queue");

    // bind the queue to the exchange
    channel.bindQueue("my-exchange", "my-queue", "my-routing-key");

    // publish a message
    std::string message = "Hello, RabbitMQ!";

    channel.publish("my-exchange", "my-routing-key", message);
  }

  void onError(AMQP::Connection* connection, const char* message) override
  {
    std::cerr << "AMQP error: " << message << std::endl;
  }

  virtual void onClosed(AMQP::Connection* connection)
  {

  }
};

int main()
{
  MyConnectionHandler handler;

  // create a AMQP connection object
  //AMQP::Connection connection(&handler, AMQP::Address("amqp://admin:[email protected]/"));

  AMQP::Address address("amqp://admin:[email protected]:5672/");
  AMQP::Connection connection(&handler, address);
  //AMQP::Login login("admin", "nimda");
  //AMQP::Connection connection(&handler, login, "10.10.50.242");

  handler.onReady(&connection);

  return 0;
}

@lukebakken
Copy link

@gunhak01. Please create a repository on GitHub - https://github.com/gunhak01?tab=repositories

Commit ALL of your code, your Visual Studio project, Makefiles, dependencies ... EVERYTHING. I should only have to clone your project and either open it in Visual Studo or run make or run nmake.

I'm happy to assist but right now you're asking me to set up a build environment when presumably you have already done so.

@gunhak01
Copy link
Author

gunhak01 commented Mar 3, 2023

@lukebakken https://github.com/gunhak01/amqpcpp_pilot
Yes, thank you. I've uploaded it to GitHub, but it doesn't seem to upload the libraries I received via vcpkg?

vcpkg install amqpcpp:x64-windows
vcpkg install libuv:x64-windows
vcpkg integrate install

vcpkglist

I got the libraries as above and am using them in visual studio and that code and vcpkg is all I ran. I didn't make any other environment modifications.

@lukebakken
Copy link

Thank you. I will find time to test this out next week. Please be patient. I suggest closing this issue (#494) and we can continue discussion in your repository.

@gunhak01
Copy link
Author

gunhak01 commented Mar 5, 2023

@lukebakken Okay, I really appreciate your help.

@gunhak01 gunhak01 closed this as completed Mar 5, 2023
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

2 participants