Skip to content

Instantly share code, notes, and snippets.

from zato.client import AnyServiceInvoker
class ZatoMiddleware(object):
def process_request(self, req):
req.zato_client = AnyServiceInvoker('http://localhost:17010',
'/django/sample', ('django-app', 'django-password'))
@dsuch
dsuch / rates.html
Last active December 18, 2015 13:29
<form action="." method="get">
From EUR to
<input type="text" name="to" value="{{ to }}" />
<input type="submit" value="Get exchange rates" />
</form>
<table id="rates">
<tr>
<th>Provider</th>
<th>Rate</th>
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function, unicode_literals
# stdlib
from datetime import datetime
from traceback import format_exc
# anyjson
from anyjson import loads
$ zato service invoke /opt/server1/ zato.security.basic-auth.get-list \
--payload '{"cluster_id":1}'
[{u'username': u'admin.invoke', u'is_active': True,
u'realm': u'Zato admin invoke', u'id': 1L, u'name': u'admin.invoke'},
{u'username': u'pubapi', u'is_active': True, u'realm': u'Zato public API',
u'id': 2L, u'name': u'pubapi'}]
$
$ zato service invoke /opt/server1 zato.security.basic-auth.get-list \
--data-format xml \
--payload '<zato_security_basic_auth_get_list_request><cluster_id>1</cluster_id>\
</zato_security_basic_auth_get_list_request>'
<zato_security_basic_auth_get_list_response xmlns="https://zato.io/ns/20130518">
<zato_env>
<cid>K034857440351657368008263132215876374901</cid>
<result>ZATO_OK</result>
</zato_env>
@dsuch
dsuch / haproxy.conf
Created June 26, 2013 22:18
HAProxy config for URL-based rate limiting
# At most 10 concurrent connections from a client
acl too_fast fe_sess_rate ge 10
# Matches any path beginning with a given prefix
acl bursts_inclined path_beg -i /client1
# Effectively working as a delay mechanism for clients that are too fast
tcp-request inspect-delay 1000ms
# Fast-path - accept connection if it's not this troublesome client
@dsuch
dsuch / front_http_plain.conf
Last active January 23, 2019 10:38
Default frontend for HAProxy
frontend front_http_plain
mode http
default_backend bck_http_plain
acl too_fast fe_sess_rate ge 10
acl bursts_inclined path_beg -i /client1
tcp-request inspect-delay 1000ms
tcp-request content accept unless bursts_inclined too_fast
from zato.server.service import Service
class MyService(Service):
def handle(self):
# JMS WebSphere MQ
self.outgoing.jms_wmq.conn.send(self.request.payload, 'JMS MQ app', 'QUEUE.1')
# AMQP
self.outgoing.amqp.conn.send(self.request.payload, 'AMQP app', 'EXCH.1', '/')
@dsuch
dsuch / stockmarket.py
Created July 6, 2013 10:38
Code for Zato article on InfoQ http://www.infoq.com/articles/zato
# anyjson
from anyjson import loads
# bunch
from bunch import bunchify
# decimal
from decimal import Decimal
# lxml
@dsuch
dsuch / xmlsec_api.py
Created July 8, 2013 17:34
Designing XML-Security API
from zato.server.service import Service
class MyService(Service):
def handle(self):
# message to decrypt defaults to self.request.raw_request
decrypted = self.xmlsec.decrypt('key-alias')
# no default message to decrypt
encrypted = self.xmlsec.encrypt('key-alias', 'message')