Skip to content

Commit

Permalink
Adding an apache license to all relevant files
Browse files Browse the repository at this point in the history
  • Loading branch information
IanCal committed Nov 10, 2011
1 parent 2132867 commit 20597fd
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 11 deletions.
10 changes: 6 additions & 4 deletions README.markdown
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
SEMQ

SEMQ is a simple message queue system built in erlang. The purpose is to allow fast push-based text communication between systems capable of basic HTTP requests. All functionality will be available to a client capable of only GET requests.
SEMQ is a simple message queue system built in erlang. The purpose is to allow fast push-based text communication between systems capable of basic (GET and POST) HTTP requests.

You are able to do two things.
You are able to do three things.


1) Put a message on a named queue. If the queue does not exist, it will be created for you.

2) Get the next message in a queue (this will delete the message). If no queue exists it will be created.

3) Get a list of all currently active queues (note : there may be no client connected to a queue)

If you try and get a message from an empty queue, then the server will wait until either 30s have passed or a message is pushed onto the queue. This enables a simple client to get messages pushed to it instead of using quick polling.

After 5 minutes of inactivity on a queue, it will get destroyed and any messages on it will be cleared.
Expand Down Expand Up @@ -71,14 +73,14 @@ Other Implementations
Pseudo code for a client waiting for information:

while true:
message = http.get("http://messageserver/myqueuename")
message = http.get("http://messageserver/queue/myqueuename")
if (message):
onMessageCallback(message)

Or an asynchronous version:

function makeRequest() :
httpRequest = http.get("http://messageserver/myqueuename")
httpRequest = http.get("http://messageserver/queue/myqueuename")
httpRequest.onSuccess = onSuccess
httpRequest.onError = onError

Expand Down
14 changes: 14 additions & 0 deletions src/frontend.erl
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
% Copyright 2011 Ian Calvert
%
% Licensed under the Apache License, Version 2.0 (the "License");
% you may not use this file except in compliance with the License.
% You may obtain a copy of the License at
%
% http://www.apache.org/licenses/LICENSE-2.0
%
% Unless required by applicable law or agreed to in writing, software
% distributed under the License is distributed on an "AS IS" BASIS,
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
% See the License for the specific language governing permissions and
% limitations under the License.

-module(frontend).
-import(routing).
-export([getrequest/1, postrequest/2, deleterequest/1, get_all_queue_names/0, removehead/1]).
Expand Down
28 changes: 28 additions & 0 deletions src/messagequeue.erl
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
% Copyright 2011 Ian Calvert
%
% Licensed under the Apache License, Version 2.0 (the "License");
% you may not use this file except in compliance with the License.
% You may obtain a copy of the License at
%
% http://www.apache.org/licenses/LICENSE-2.0
%
% Unless required by applicable law or agreed to in writing, software
% distributed under the License is distributed on an "AS IS" BASIS,
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
% See the License for the specific language governing permissions and
% limitations under the License.

% Copyright 2011 Ian Calvert
%
% Licensed under the Apache License, Version 2.0 (the "License");
% you may not use this file except in compliance with the License.
% You may obtain a copy of the License at
%
% http://www.apache.org/licenses/LICENSE-2.0
%
% Unless required by applicable law or agreed to in writing, software
% distributed under the License is distributed on an "AS IS" BASIS,
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
% See the License for the specific language governing permissions and
% limitations under the License.

-module(messagequeue).
-export([new/0]).
-define(TIMEOUT, 300000).
Expand Down
14 changes: 13 additions & 1 deletion src/routing.erl
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
%% Code largely taken from http://www.metabrew.com/article/a-million-user-comet-application-with-mochiweb-part-1
% Copyright 2011 Ian Calvert
%
% Licensed under the Apache License, Version 2.0 (the "License");
% you may not use this file except in compliance with the License.
% You may obtain a copy of the License at
%
% http://www.apache.org/licenses/LICENSE-2.0
%
% Unless required by applicable law or agreed to in writing, software
% distributed under the License is distributed on an "AS IS" BASIS,
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
% See the License for the specific language governing permissions and
% limitations under the License.

-module(routing).
-behaviour(gen_server).
Expand Down
21 changes: 15 additions & 6 deletions src/semq_web.erl
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
%% @author Mochi Media <[email protected]>
%% @copyright 2010 Mochi Media <[email protected]>
% Copyright 2011 Ian Calvert
%
% Licensed under the Apache License, Version 2.0 (the "License");
% you may not use this file except in compliance with the License.
% You may obtain a copy of the License at
%
% http://www.apache.org/licenses/LICENSE-2.0
%
% Unless required by applicable law or agreed to in writing, software
% distributed under the License is distributed on an "AS IS" BASIS,
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
% See the License for the specific language governing permissions and
% limitations under the License.

%% @doc Web server for semq.

-module(semq_web).
-author("Mochi Media <[email protected]>").

-export([start/1, stop/0, loop/2]).
-import(frontend).
Expand Down Expand Up @@ -32,7 +41,7 @@ delete_request(Req, Queue) ->

get_request(Req, Queue) ->
case frontend:getrequest(Queue) of
{ok, Message} ->
{ok, {content_type : ContentType, message : Message}} ->
Socket = Req:get(socket),
case gen_tcp:recv(Socket, 0, 0) of
{error, 'timeout'} ->
Expand All @@ -52,7 +61,7 @@ listqueues_request(Req) ->
Req:respond({200, headers(), io_lib:format("~p~n", [Queues])}).

post_request(Req, Queue, Message) ->
frontend:postrequest(Queue, Message),
frontend:postrequest(Queue, {content_type : Req:get_header_value('content-type'), message : Message}),
Req:respond({200, [{"Content-Type", "text/plain"}], "Posted"}).

process_request("unique_queue_name", Req) ->
Expand Down

0 comments on commit 20597fd

Please sign in to comment.