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

Issue in data publishing #1

Open
rakshita1006 opened this issue Jan 15, 2021 · 9 comments
Open

Issue in data publishing #1

rakshita1006 opened this issue Jan 15, 2021 · 9 comments

Comments

@rakshita1006
Copy link

Hi,

I am trying to create a pub/sub model using BoostAsio library with the help of your code.

I was able to establish a connection between the publisher and subscriber but the data is neither [published nor subscribe.

Could you please help me with the issue.

Thanks & Regards
Rakshita Parihar

@rakshita1006
Copy link
Author

Please help me with the solution!!!

@sehe
Copy link

sehe commented Jan 19, 2021

Please help me with the solution!!!

Heads up: shouting isn't help. Nobody is obliged to solve your issues in any time frame. This is just a free project that you opt to use. I'm not a maintainer here, but I thought I'd let you know.

@sehe
Copy link

sehe commented Jan 19, 2021

ON TOPIC: This question was raised on StackOverflow and I analyzed its cause.

The problem is that msghub_impl does not own the io service, YET insists on starting service threads (even when threads==0). This causes the service to complete all work before even posting the first async task, and a subsequent run() (e.g. from main()) simply has no effect (as per the documentation, the same applies to io_service in older versions.).

sehe referenced this issue in sehe/msghub Jan 20, 2021
Adds a work_ object to avoid prematurely exiting io_service
sehe referenced this issue in sehe/msghub Jan 20, 2021
Adds a work_ object to avoid prematurely exiting io_service
@rakshita1006
Copy link
Author

Hi,
Thanks for the reply
I tried to do all the changes in my code as suggested in above files but still data is not published.

@sehe
Copy link

sehe commented Jan 31, 2021

@rakshita1006 can you run the tests? What are you doing different/y? Note also, I have made a fork that has some simplifications in the API. It is still on-the-wire compatible though (until this: sehe#1)

@rakshita1006
Copy link
Author

rakshita1006 commented Feb 5, 2021

Hi,

I am not sure what wrong I am doing .I am using Ubuntu 18.0 with boost 1.65.0.
I downloaded the code(zipfolder) and created by own clientmain.cpp & servermain.cpp.
I included all the relevant header & Library files and compiled the code.The compilation was successful but i am not getting published message.

I also made the necessary changes as suggested by you in fix issue #1,#3 ,#4 and try to run the code.

client code:
#include <boost/asio.hpp>
#include <msghub.h>
using namespace std::chrono_literals;

int main() {
boost::asio::io_service io_service;
boost::asio::io_service::work work(io_service);
{
msghub msghub(io_service);

    msghub.connect("localhost", 1334);
    assert(!io_service.stopped()); // no longer fails due to `work`
    msghub.publish("Publish", "new message");
    io_service.run_one();
}
io_service.run();

}

Server Code:
void on_message(const std::string& topic, std::vector& message)
{
// handle message
}

int main()
{
	boost::asio::io_service io_service;
	// Create hub to listen on 0xbee port
	msghub msghub(io_service);
	msghub.create(1334);
	// Subscribe on "any topic"
	msghub.subscribe("Publish", on_message);
	// Current or any another client
	//msghub.publish("Publish", "new message");
	io_service.run();
}

Please find the attched file of the output
Output
server:
output1
client:
output2

U ran the code with the same code as here.

Is it the correct way to go or I am missing some step?Does we need to execute code from test folder.if yes then how as there is no main function in that?

Thanks
Rakshita

@sehe
Copy link

sehe commented Feb 9, 2021

@rakshita1006

What happens when you check out the code from the PR branch and run the tests?

I've added another commit that you can use instead of manually doing the changes: #7

You can use it from my repo, e.g. in a docker:

docker run --rm -ti ubuntu:20.04
apt update
apt -qqyy install build-essential git cmake libboost-all-dev
git clone https://github.com/sehe/msghub -b cmake
cd msghub
cmake . && make
./examples/server & ./examples/client ; kill %1; wait

The tester has a main function (it's in main.cpp) and depends on Boost Unit Test framework.. is also built by the CMake

@sehe
Copy link

sehe commented Feb 10, 2021

Making it even easier, I reduced CMake and Boost requirements to support 18.04 again, and tested with a Dockerfile:

FROM ubuntu:18.04
ENV DEBIAN_FRONTEND=noninteractive
RUN \
        apt update; \
        apt -qqyy install build-essential git cmake libboost-all-dev

RUN git clone https://github.com/sehe/msghub --depth 1 -b cmake
WORKDIR /msghub
RUN cmake . && make

CMD ["/bin/bash", "-c", "(./examples/server & ./examples/client ; kill %1; wait)"]

Put this Dockerfile somewhere and build it:

docker build . -f containers/issue1 -t msghub:cmake

To do the simple client/server test:

docker run --rm -it msghub:cmake

There are shutdown races impactng the unit tests. I think they're all fixed on my other branch sehe/msghub: https://github.com/sehe/msghub/blob/std-over-boost/containers/std-over-boost

Live demo of the cmake container :
small-cmake

Live demo of the std-over-boost branch which fixes a lot more issues and modernizes the code + interfaces:

small-std-over-boost

@rakshita1006
Copy link
Author

@sehe It finally worked for me. Thank you for your help.

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