AMQP Filter for Azure Event Hubs with Apache Qpid Proton

There is no a lot of documentation and examples how to deal with AMQP filters by using qpid-proton (Proton C API).

Deffierent approaches for working with Azure Event Hub are well described by the following link: Using Amqp.Net Lite with Azure Service Bus Event Hubs.

In my practice I’m using qpid-proton 0.8. To set the filter for retriving messages from Event Hub by timestamp offsset:

pn_messenger_t *m_messenger = pn_messenger(NULL);

// ...

// About addresses and filters for Azure Event Hubs: 
// https://amqpnetlite.codeplex.com/wikipage?title=Using%20Amqp.Net%20Lite%20with%20Azure%20Server%20Bus%20Event%20Hub&referringTitle=Documentation
char address[] = "amqps://user:password@host:port/path";
char filter_section[] = "apache.org:selector-filter:string";
// timestamp in milliseconds
char filter_value[] = "amqp.annotation.x-opt-enqueuedtimeutc >= '1422627183000'";

// ...

pn_subscription_t *subsribtion = pn_messenger_subscribe(m_messenger, address);

// get a link and the source endpoint (terminus)
pn_link_t 	*link = pn_messenger_get_link(m_messenger, address, false);
pn_terminus_t	*link_source = pn_link_source(link);
pn_data_t	*link_source_filter_data = pn_terminus_filter(link_source);

pn_data_put_map(link_source_filter_data);
  // add a filter entry
  pn_data_enter(link_source_filter_data);
  // symbol key
  pn_data_put_symbol(link_source_filter_data, pn_bytes(strlen(filter_section), filter_section));
  // described value
  pn_data_put_described(link_source_filter_data);
    pn_data_enter(link_source_filter_data);
    pn_data_put_symbol(link_source_filter_data, pn_bytes(strlen(filter_section), filter_section));
    // filter expression as a string
    pn_data_put_string(link_source_filter_data, pn_bytes(strlen(filter_value), filter_value));
  pn_data_exit(link_source_filter_data);

pn_messenger_start(m_messenger);
	
// ... 
	
// here we'll receive only messages with annotation.x-opt-enqueuedtimeutc >= '1422627183000'
pn_messenger_recv(m_messenger, MESSAGES_COUNT);
	
// ...

You can get binaries of qpid-proton 0.8 as NuGet package which are compiled for processors with IA32 instructions set (I need it for my Intel Galileo Gen2 projects).

Recursive graphics in Turbo C++ 3.0

This code is using graphics.lib library and requires Borland Graphics Interface. I was using for my tests EGAVGA.bgi copied to from Turbo C++ 3.0 BGI\ folder (if you do not want to copy .bgi file to the folder with your application you can precise the path in initgraph() third argument).

#include <stdio.h>
#include <stdlib.h>
#include <graphics.h>
#include <math.h>
/*
x,y - center coordinated
n - rays count
level - subrays level number
*/
void snowflake(int x, int y, int n, int level)  {
	if (level == 4) return; // the level 4 is maximum
	int i, nx, ny;
	float dAngel = 2.0 * M_PI/n ; // agnle step

	for(i=0;i<n;i++) {

	  setcolor(random(14) + 1); // random color
	 
	  // drawing the line
	  moveto(x,y);
	  nx = x + floor((200/(level*level))*sin((float)i*dAngel + level - 1) );
	  ny = y - floor((200/(level*level))*cos((float)i*dAngel + level - 1) );
	  lineto(nx,ny);
	  
	  //recursive call for sublevel
	  snowflake(nx,ny,n,level+1);
	}
}

int main() {
	int gd = DETECT, gm ;
	initgraph(&gd,&gm,""); // graphics initialization, put here the path to BGI if needed
	snowflake(getmaxx()/2,getmaxy()/2,12,1); // drawing our recursive showflake
	closegraph(); // properly closing graphics interface
	return 0;
}