in Education by
I use "github.com/streadway/amqp" for async processing requests via queue (RabbitMQ). And I use "github.com/gorilla/rpc" to register my service without workaround, but I have to use ugly solution for conversion amqp.Delivery to http.Request (mux.Server can works with http.Request only). Can I use more elegant solution for this task? I can't find JSON RPC router for AMQP. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
First, RPC and pub-sub (e.g. AMQP) are two very different beasts; trying to use one to implement the other isn't necessarily wrong or bad, but it's definitely suspicious, and implies that there could be a breakdown somewhere in the design. So I would highly recommend reconsidering the design starting with your business goals and make sure that what you're trying to implement is actually the correct way to achieve the desired functionality. That said, what you're describing is basically possible, but you want to move your abstraction up a level. Trying to send a http.Request via AMQP is mixing protocols in a way that's only going to lead to more problems. The cleaner way to implement this behavior would be to have an HTTP handler that handles http.Requests (as normal), and a AMQP handler that handles amqp.Deliverys (as normal), and have each of those handlers call a shared business logic handler which deals only in your domain model. So, your HTTP handler would parse an HTTP request and turn it into a domain object - you don't give any concrete details in the question so I'll invent something like maybe myapp.UserRegistration. Your HTTP handler would pass that to a myapp.UserService which would handle the actual business logic of registering a user, it would return a result, which you would then transform into the appropriate type, marshal to JSON, and send back to the client in an http.Response. myapp.UserService would know nothing about HTTP or AMQP; it operates only on your own domain types. Your AMQP handler would pick up a message, parse it into the same myapp.UserRegistration type, pass it to the same myapp.UserService handler, and get the same response back - ensuring that the business logic for AMQP and HTTP behaves the same way. Then you'd get your response back, and... well, this is AMQP, so you don't get to send a response to the client. I don't know your setup, maybe you have another queue you can send the response back on, maybe you don't care about the response and can discard it. This is where the difference between RPC and AMQP is most apparent. This also makes your business logic, HTTP handler, and AMQP handler more testable in isolation because you're separating the protocol logic from the business logic, which can be helpful even when you aren't trying to deal with multiple protocols (i.e. it's not a bad idea even if you're only doing HTTP) I hope that at least gives you enough info to put you on the right track in your implementation. Good luck!

Related questions

0 votes
    Having a Golang project and Go workspace. I'm trying to run my test, but I'm having the following ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    So I am trying to build a docker image with the Golang SDK, everything runs except the section in ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 17, 2022 in Education by JackTerrance
0 votes
    Will it be tedious to work with golang in machine learning? What could be a best start? Select the correct answer from above options...
asked Dec 1, 2021 in Education by JackTerrance
0 votes
    I'm relatively new to go, and I'm looking for a rough equivalent (library or implementation) of ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 13, 2022 in Education by JackTerrance
0 votes
    I'm relatively new to go, and I'm looking for a rough equivalent (library or implementation) of ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 12, 2022 in Education by JackTerrance
0 votes
    I am trying to create a "feature branch" from golang. The following code is not working: reader : ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 9, 2022 in Education by JackTerrance
0 votes
    What is the difference between JAX--WS and JAX-RPC?...
asked Jun 6, 2021 in Technology by JackTerrance
0 votes
    Which of the following is true about Web Services RPC? A - Web services allow clients to invoke procedures, functions, and methods ... or a .NET component. D - All of the above....
asked Jan 12, 2021 in Technology by JackTerrance
0 votes
    Is XML-RPC is platform-dependent?...
asked Nov 7, 2020 in Education by Editorial Staff
0 votes
    What are the features of XML-RPC?...
asked Nov 7, 2020 in Education by Editorial Staff
0 votes
    How response is sent in XML-RPC?...
asked Nov 7, 2020 in Education by Editorial Staff
0 votes
    How request is sent in XML-RPC?...
asked Nov 7, 2020 in Education by Editorial Staff
0 votes
    What is XML-RPC?...
asked Nov 7, 2020 in Education by Editorial Staff
0 votes
    What is RPC in Google Analytics?...
asked Oct 3, 2020 in Technology by JackTerrance
0 votes
    When working with Ajax applications, which is faster, XML or JSON? A. XML, because it is extensible B. JSON, ... D. JSON, because it is already parsed into a JavaScript object...
asked Mar 10, 2023 in Technology by JackTerrance
...