Building social trading app as part of Akka Serverless Hackathon. Architecture will be added later
This repository contains the Trade Service. Trade has the following properties:
trade_id (string)
buyer_user_id(string)
seller_user_id(string)
buyer_item_ids(string list)
seller_item_ids(string list)
trade_offered_timestamp(int64)
status[CREATED, ACCEPTED, REJECTED)
CreateTrade
AcceptTrade
RejectTrade
GetTrade
TradeOffered
TradeAccepted
TradeRejected
TradeOffered
TradeAccepted
TradeRejected
getTradeByUser
- Query: select* from trade_by_user where user_id = :user_id
To build, at a minimum you need to generate and process sources, particularly when using an IDE. A convenience is compile your project:
mvn compile
In order to run your application locally, you must run the Akka Serverless proxy. The included docker-compose
file contains the configuration required to run the proxy for a locally running application.
It also contains the configuration to start a local Google Pub/Sub emulator that the Akka Serverless proxy will connect to.
To start the proxy, run the following command from this directory:
docker-compose up
On Linux this requires Docker 20.10 or later (moby/moby#40007), or for a
USER_FUNCTION_HOST
environment variable to be set manually.
docker-compose -f docker-compose.yml -f docker-compose.linux.yml up
To start the application locally, the exec-maven-plugin
is used. Use the following command:
mvn compile exec:java
Note - You can also directly use http call to do the same actions. For example to get the cart: localhost:9000/carts/3232
grpcurl \
-d '{"tradeId": "1212", "buyerUserId": "3", "sellerUserId": "5", "buyerItemIds" : [{"itemId" : "1"}, {"itemId" : "2"}], "sellerItemIds" : [{"itemId" : "10"}, {"itemId" : "12"}]}' \
-plaintext localhost:9000 \
com.lightbend.gsa.trade.TradeService.CreateTrade
Output:
{
}
grpcurl \
-d '{"tradeId": "1212"}' \
-plaintext localhost:9000 \
com.lightbend.gsa.trade.TradeService.GetTrade
Output:
{
"trade_id": "1212",
"buyer_user_id": "3",
"seller_user_id": "5",
"buyer_item_ids": [
{
"item_id": "1"
},
{
"item_id": "2"
}
],
"seller_item_ids": [
{
"item_id": "10"
},
{
"item_id": "12"
}
],
"trade_offered_timestamp": "1624642878834"
}
grpcurl \
-d '{"tradeId": "1212"}' \
-plaintext localhost:9000 \
com.lightbend.gsa.trade.TradeService.AcceptTrade
Output:
{
}
grpcurl \
-d '{"tradeId": "1212"}' \
-plaintext localhost:9000 \
com.lightbend.gsa.trade.TradeService.GetTrade
Output:
{
"trade_id": "1212",
"buyer_user_id": "3",
"seller_user_id": "5",
"buyer_item_ids": [
{
"item_id": "1"
},
{
"item_id": "2"
}
],
"seller_item_ids": [
{
"item_id": "10"
},
{
"item_id": "12"
}
],
"trade_offered_timestamp": "1624642920511",
"status": "ACCEPTED"
}
grpcurl \
-d '{"tradeId": "113", "buyerUserId": "1", "sellerUserId": "3", "buyerItemIds" : [{"itemId" : "8"}, {"itemId" : "11"}], "sellerItemIds" : [{"itemId" : "2"}, {"itemId" : "6"}]}' \
-plaintext localhost:9000 \
com.lightbend.gsa.trade.TradeService.CreateTrade
Output:
{
}
grpcurl \
-d '{"tradeId": "113"}' \
-plaintext localhost:9000 \
com.lightbend.gsa.trade.TradeService.GetTrade
Output:
{
"trade_id": "113",
"buyer_user_id": "1",
"seller_user_id": "3",
"buyer_item_ids": [
{
"item_id": "8"
},
{
"item_id": "11"
}
],
"seller_item_ids": [
{
"item_id": "2"
},
{
"item_id": "6"
}
],
"trade_offered_timestamp": "1624643005560"
}
grpcurl \
-d '{"tradeId": "113"}' \
-plaintext localhost:9000 \
com.lightbend.gsa.trade.TradeService.RejectTrade
Output:
{
}
grpcurl \
-d '{"tradeId": "113"}' \
-plaintext localhost:9000 \
com.lightbend.gsa.trade.TradeService.GetTrade
Output:
{
"trade_id": "113",
"buyer_user_id": "1",
"seller_user_id": "3",
"buyer_item_ids": [
{
"item_id": "8"
},
{
"item_id": "11"
}
],
"seller_item_ids": [
{
"item_id": "2"
},
{
"item_id": "6"
}
],
"trade_offered_timestamp": "1624643005560",
"status": "REJECTED"
}
grpcurl \
-d '{"userId": "1"}' \
-plaintext localhost:9000 \
com.lightbend.gsa.trade.view.TradeViewService.GetTradeByUserId
Output:
{
"trade_id": "113",
"buyer_user_id": "1",
"seller_user_id": "3",
"buyer_item_ids": [
{
"item_id": "8"
},
{
"item_id": "11"
}
],
"seller_item_ids": [
{
"item_id": "2"
},
{
"item_id": "6"
}
],
"trade_offered_timestamp": "1624643005571",
"status": "REJECTED"
}
grpcurl \
-d '{"userId": "5"}' \
-plaintext localhost:9000 \
com.lightbend.gsa.trade.view.TradeViewService.GetTradeByUserId
Output:
{
"trade_id": "1212",
"buyer_user_id": "3",
"seller_user_id": "5",
"buyer_item_ids": [
{
"item_id": "1"
},
{
"item_id": "2"
}
],
"seller_item_ids": [
{
"item_id": "10"
},
{
"item_id": "12"
}
],
"trade_offered_timestamp": "1624643493608",
"status": "ACCEPTED"
}
To deploy your service, install the akkasls
CLI as documented in
mvn clean install -Dmaven.test.skip=true
mvn clean install
docker push {docker-username}/{project-name}
akkasls auth login
akkasls config set project <project-name>
akkasls services deploy <servicename> docker.io/{docker-username}/{project-name}
akkasls service expose <servicename> --enable-cors
Output:
Service <servicename> was successfully exposed at: exampleABCD.us-east1.apps.akkaserverless.io
grpcurl -d '{"tradeId": "1212", "buyerUserId": "3", "sellerUserId": "5", "buyerItemIds" : [{"itemId" : "1"}, {"itemId" : "2"}], "sellerItemIds" : [{"itemId" : "10"}, {"itemId" : "12"}]}' exampleABCD.us-east1.apps.akkaserverless.io:443 com.lightbend.gsa.trade.TradeService.CreateTrade
Output:
{
}
grpcurl -d '{"tradeId": "1212"}' exampleABCD.us-east1.apps.akkaserverless.io:443 com.lightbend.gsa.trade.TradeService.GetTrade
Output:
{
"trade_id": "1212",
"buyer_user_id": "3",
"seller_user_id": "5",
"buyer_item_ids": [
{
"item_id": "1"
},
{
"item_id": "2"
}
],
"seller_item_ids": [
{
"item_id": "10"
},
{
"item_id": "12"
}
],
"trade_offered_timestamp": "1624645398129"
}
grpcurl -d '{"tradeId": "1212"}' exampleABCD.us-east1.apps.akkaserverless.io:443 com.lightbend.gsa.trade.TradeService.AcceptTrade
Output:
{
}
grpcurl -d '{"tradeId": "1212"}' exampleABCD.us-east1.apps.akkaserverless.io:443 com.lightbend.gsa.trade.TradeService.GetTrade
Output:
{
"trade_id": "1212",
"buyer_user_id": "3",
"seller_user_id": "5",
"buyer_item_ids": [
{
"item_id": "1"
},
{
"item_id": "2"
}
],
"seller_item_ids": [
{
"item_id": "10"
},
{
"item_id": "12"
}
],
"trade_offered_timestamp": "1624645457811",
"status": "ACCEPTED"
}
grpcurl -d '{"tradeId": "113", "buyerUserId": "1", "sellerUserId": "3", "buyerItemIds" : [{"itemId" : "8"}, {"itemId" : "11"}], "sellerItemIds" : [{"itemId" : "2"}, {"itemId" : "6"}]}' exampleABCD.us-east1.apps.akkaserverless.io:443 com.lightbend.gsa.trade.TradeService.CreateTrade
Output:
{
}
grpcurl -d '{"tradeId": "113"}' exampleABCD.us-east1.apps.akkaserverless.io:443 com.lightbend.gsa.trade.TradeService.GetTrade
Output:
{
"trade_id": "113",
"buyer_user_id": "1",
"seller_user_id": "3",
"buyer_item_ids": [
{
"item_id": "8"
},
{
"item_id": "11"
}
],
"seller_item_ids": [
{
"item_id": "2"
},
{
"item_id": "6"
}
],
"trade_offered_timestamp": "1624645631208"
}
grpcurl -d '{"tradeId": "113"}' exampleABCD.us-east1.apps.akkaserverless.io:443 com.lightbend.gsa.trade.TradeService.RejectTrade
Output:
{
}
grpcurl -d '{"tradeId": "113"}' exampleABCD.us-east1.apps.akkaserverless.io:443 com.lightbend.gsa.trade.TradeService.GetTrade
Output:
{
"trade_id": "113",
"buyer_user_id": "1",
"seller_user_id": "3",
"buyer_item_ids": [
{
"item_id": "8"
},
{
"item_id": "11"
}
],
"seller_item_ids": [
{
"item_id": "2"
},
{
"item_id": "6"
}
],
"trade_offered_timestamp": "1624645678491",
"status": "REJECTED"
}
grpcurl -d '{"userId": "1"}' exampleABCD.us-east1.apps.akkaserverless.io:443 com.lightbend.gsa.trade.view.TradeViewService.GetTradeByUserId
Output:
{
"trade_id": "113",
"buyer_user_id": "1",
"seller_user_id": "3",
"buyer_item_ids": [
{
"item_id": "8"
},
{
"item_id": "11"
}
],
"seller_item_ids": [
{
"item_id": "2"
},
{
"item_id": "6"
}
],
"trade_offered_timestamp": "1624645600890",
"status": "REJECTED"
}
grpcurl -d '{"userId": "5"}' exampleABCD.us-east1.apps.akkaserverless.io:443 com.lightbend.gsa.trade.view.TradeViewService.GetTradeByUserId
Output:
{
"trade_id": "1212",
"buyer_user_id": "3",
"seller_user_id": "5",
"buyer_item_ids": [
{
"item_id": "1"
},
{
"item_id": "2"
}
],
"seller_item_ids": [
{
"item_id": "10"
},
{
"item_id": "12"
}
],
"trade_offered_timestamp": "1624645328653",
"status": "ACCEPTED"
}