100% found this document useful (2 votes)
73 views55 pages

[Ebooks PDF] download Hands-on Azure Functions with C#: Build Function as a Service (FaaS) Solutions 1st Edition Ashirwad Satapathi full chapters

Azure

Uploaded by

nardiellermi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
100% found this document useful (2 votes)
73 views55 pages

[Ebooks PDF] download Hands-on Azure Functions with C#: Build Function as a Service (FaaS) Solutions 1st Edition Ashirwad Satapathi full chapters

Azure

Uploaded by

nardiellermi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 55

Download Full Version ebook - Visit ebookmeta.

com

Hands-on Azure Functions with C#: Build Function


as a Service (FaaS) Solutions 1st Edition Ashirwad
Satapathi

https://ebookmeta.com/product/hands-on-azure-functions-with-
c-build-function-as-a-service-faas-solutions-1st-edition-
ashirwad-satapathi/

OR CLICK HERE

DOWLOAD NOW

Discover More Ebook - Explore Now at ebookmeta.com


Instant digital products (PDF, ePub, MOBI) ready for you
Download now and discover formats that fit your needs...

Start reading on any device today!

Developing Cloud-Native Solutions with Microsoft Azure and


.NET: Build Highly Scalable Solutions for the Enterprise
1st Edition Ashirwad Satapathi
https://ebookmeta.com/product/developing-cloud-native-solutions-with-
microsoft-azure-and-net-build-highly-scalable-solutions-for-the-
enterprise-1st-edition-ashirwad-satapathi/
ebookmeta.com

Microsoft Azure for Java Developers: Deploying Java


Applications through Azure WebApp, Azure Kubernetes
Service, Azure Functions, and Azure Spring Cloud 1st
Edition Abhishek Mishra
https://ebookmeta.com/product/microsoft-azure-for-java-developers-
deploying-java-applications-through-azure-webapp-azure-kubernetes-
service-azure-functions-and-azure-spring-cloud-1st-edition-abhishek-
mishra/
ebookmeta.com

Integrating Serverless Architecture: Using Azure


Functions, Cosmos DB, and SignalR Service 1st Edition Rami
Vemula
https://ebookmeta.com/product/integrating-serverless-architecture-
using-azure-functions-cosmos-db-and-signalr-service-1st-edition-rami-
vemula-2/
ebookmeta.com

Dessert A Tale of Happy Endings 1st Edition Jeri Quinzio

https://ebookmeta.com/product/dessert-a-tale-of-happy-endings-1st-
edition-jeri-quinzio/

ebookmeta.com
MT6360 PMIC Datasheet Version 1 1 Release date 2019 05 24
Mediatek Inc

https://ebookmeta.com/product/mt6360-pmic-datasheet-
version-1-1-release-date-2019-05-24-mediatek-inc/

ebookmeta.com

Getting to Know Vue.js: Learn to Build Single Page


Applications in Vue from Scratch 1st Edition Brett Nelson

https://ebookmeta.com/product/getting-to-know-vue-js-learn-to-build-
single-page-applications-in-vue-from-scratch-1st-edition-brett-nelson/

ebookmeta.com

Greed An Amber Monroe Crime Thriller Book 1 Sutter C M

https://ebookmeta.com/product/greed-an-amber-monroe-crime-thriller-
book-1-sutter-c-m/

ebookmeta.com

Next in Line US Edition Jeffrey Archer

https://ebookmeta.com/product/next-in-line-us-edition-jeffrey-archer/

ebookmeta.com

Shipwrecks Of Lake Erie Tragedy In The Quadrangle 1st


Edition David Frew

https://ebookmeta.com/product/shipwrecks-of-lake-erie-tragedy-in-the-
quadrangle-1st-edition-david-frew/

ebookmeta.com
Creole Societies in the Portuguese Colonial Empire 1st
Edition Philip J. Havik

https://ebookmeta.com/product/creole-societies-in-the-portuguese-
colonial-empire-1st-edition-philip-j-havik/

ebookmeta.com
Ashirwad Satapathi and Abhishek Mishra

Hands-on Azure Functions with C#


Build Function as a Service (FaaS) Solutions
1st ed.
Ashirwad Satapathi
Gajapati, Odisha, India

Abhishek Mishra
Mumbai, Maharashtra, India

ISBN 978-1-4842-7121-6 e-ISBN 978-1-4842-7122-3


https://doi.org/10.1007/978-1-4842-7122-3

© Ashirwad Satapathi and Abhishek Mishra 2021

This work is subject to copyright. All rights are solely and exclusively
licensed by the Publisher, whether the whole or part of the material is
concerned, specifically the rights of translation, reprinting, reuse of
illustrations, recitation, broadcasting, reproduction on microfilms or in
any other physical way, and transmission or information storage and
retrieval, electronic adaptation, computer software, or by similar or
dissimilar methodology now known or hereafter developed.

The use of general descriptive names, registered names, trademarks,


service marks, etc. in this publication does not imply, even in the
absence of a specific statement, that such names are exempt from the
relevant protective laws and regulations and therefore free for general
use.

The publisher, the authors and the editors are safe to assume that the
advice and information in this book are believed to be true and accurate
at the date of publication. Neither the publisher nor the authors or the
editors give a warranty, expressed or implied, with respect to the
material contained herein or for any errors or omissions that may have
been made. The publisher remains neutral with regard to jurisdictional
claims in published maps and institutional affiliations.
This Apress imprint is published by the registered company APress
Media, LLC part of Springer Nature.
The registered company address is: 1 New York Plaza, New York, NY
10004, U.S.A.
This book is dedicated to my father, Mr. Upendra Satapathi, and mother,
Mrs. Sabita Panigrahi, for supporting me through each and every phase
of my life. Without your support I wouldn’t have been able to complete
this book.
—Ashirwad Satapathi
This book is dedicated to my super dad, Mr. Balabhardra Mishra, and
loving mom, Mrs. Pragyan Mishra.
—Abhishek Mishra
Introduction
Azure Functions is a function as a service (FaaS) offering on the Azure
Platform. In this book, you will explore Azure Functions in detail and
learn how to work with Azure Functions using a practical and example-
based approach that will help you grasp the subject with ease.
The book will start with the essential topics. You will learn how to
set up the application development environment for Azure Functions.
Then you will get example-based steps for building a serverless
solution using a combination of bindings and triggers in C#. The book
will then dive into areas that will help you learn how to create custom
bindings, connect with various data sources, ingest telemetry data for
Azure Functions into Application Insights, and learn various ways to
deploy the functions to the Azure environment.
You will also explore advanced areas such as running Azure
Functions in an Azure Kubernetes Service cluster using Kubernetes
Event Driven Autoscaling (KEDA). You will learn the DevOps way of
working with Azure Functions using Azure DevOps, as well as the best
practices you should follow while using Azure Functions.
This book provides production-like scenarios and provides labs that
will deliver the right set of hands-on experience. The practical approach
in the book will help you gain deep proficiency in the subject.
This book is intended for experienced developers, cloud architects,
and tech enthusiasts looking forward to building scalable and efficient
serverless solutions using Azure Functions. Anyone having a prior
experience with C# and knowing the Azure basics can use this book to
start their journey in building serverless solutions with Azure
Functions.
Acknowledgments
We would like to thank the Apress team for giving us the opportunity to
work on this book. Also thanks to the technical reviewer and the editors
for helping us deliver this manuscript.
Table of Contents
Chapter 1:​Introduction to Azure Functions
Structure of the Chapter
Objectives
Introduction to Azure Functions
Introduction to Serverless
Azure WebJobs vs.​Azure Functions
Advantages and Disadvantages of Azure Functions
Hosting Plans for Azure Functions
Consumption Plan
Premium Plan
Dedicated Plan
Use Cases for Azure Functions
Summary
Chapter 2:​Build Your First Azure Function
Structure of the Chapter
Objectives
Create Functions Using the Azure Portal
Create Functions Locally Using the Command Line
Create Functions Using Visual Studio Code
Create Functions Using Visual Studio
Summary
Chapter 3:​What Are Triggers and Bindings?​
Structure of the Chapter
Objectives
Introduction to Triggers and Bindings
Supported Triggers and Bindings
Trigger and Binding Use Cases
Use Case:​An Azure function gets triggered when a message
arrives in a queue, and the processed message is put into
another queue
Use Case:​A scheduled job picks up images for Blob Storage
at a particular time interval and then processes and stores
them back in the Blob Storage
Use Case:​An HTTP call invokes an Azure function to execute
some business logic
Use Case:​An event grid can invoke an Azure function to
send an email with event data
Use Case:​RabbitMQ triggers an Azure function that
processes the message sent by RabbitMQ and puts the
processed message in Azure Cosmos DB
Implement Triggers and Bindings for Azure Functions
Summary
Chapter 4:​OTP Mailer with Queue Storage Trigger and SendGrid
Binding
Structure of the Chapter
Objectives
Getting Started with a Queue Storage Trigger and Use Cases
Build a Sample Application Using a Queue Storage Trigger
Getting Started with a SendGrid Output Binding and Use Cases
Build a Sample Application Using the SendGrid Output Binding
Create an OTP Mailer Using a Queue Storage Trigger and
SendGrid Output Binding
Summary
Chapter 5:​Build a Report Generator with a Timer Trigger and Blob
Storage Bindings
Structure of the Chapter
Objectives
Getting Started with Timer Triggers and Use Cases
Build a Sample Application Using a Timer Trigger
Getting Started with Blob Storage Bindings and Use Cases
Build a Sample Function Using a Blob Storage Binding
Create a Report Generator Using a Blob Storage Binding and
Timer Trigger
Summary
Chapter 6:​To-Do API with an HTTP Trigger and a Table Storage
Binding
Structure of the Chapter
Objectives
Getting Started with HTTP Triggers and Use Cases
Build a Sample Application Using an HTTP Trigger
Routing in HTTP-Triggered Azure Functions
Getting Started with Table Storage Bindings and Use Cases
Build a Sample Application Using a Table Storage Binding
Create a To-Do API with an HTTP Trigger and a Table Storage
Binding
Summary
Chapter 7:​Creating Custom Bindings for Azure Functions
Structure of the Chapter
Objectives
Introduction to Custom Bindings
Use Cases for Custom Bindings
Build a Custom Binding for Azure Functions
Create an Azure Function
Implement the Binding Attribute Class
Implement the Binding Logic Class
Implement the Binding Extension Class
Implement the Binding Startup Class
Incorporate the Binding in the Azure Function
Summary
Chapter 8:​Building Serverless APIs Using Azure Functions and
Azure SQL
Structure of the Chapter
Objectives
Problem Statement
Creating an Azure SQL Database Instance in the Azure Portal
Building Serverless APIs for the Proof of Concept
Testing the Serverless APIs for the Proof of Concept
Summary
Chapter 9:​Serverless API Using Azure Functions and Azure
Cosmos DB
Structure of the Chapter
Objectives
Introduction to Azure Cosmos DB and Its Use Cases
Getting Started with Azure Function Cosmos DB Triggers by
Building a Simple Application
Build an HTTP-Triggered Azure Function to Perform CRUD
Operations on Azure Cosmos DB Using Bindings
Leverage the Azure Cosmos DB SDK to Interact with Cosmos DB
from Azure Functions
Summary
Chapter 10:​Enabling Application Insights and Azure Monitor
Structure of the Chapter
Objectives
Enable Logging Using Application Insights
Perform Diagnostics for Azure Functions
Monitor Azure Functions and Create Alerts
Restrict the Number of Scaling Instances for the Azure Function
App
Summary
Chapter 11:​Storing Function Secrets in Azure Key Vault
Structure of the Chapter
Objective
Getting Started with Azure Key Vault
Create an Azure Key Vault in the Azure Portal
Store Secrets in Key Vault
Create an Azure Function in the Azure Portal
Add an Access Policy for Azure Key Vault
Summary
Chapter 12:​Authentication and Authorization Using Azure Active
Directory
Structure of the Chapter
Objectives
What Is Azure Active Directory?​
What Are Authentication and Authorization?​
Implement Authentication and Authentication for Azure
Functions Using Azure Active Directory
Summary
Chapter 13:​Securing Azure Functions with API Management
Structure of the Chapter
Objectives
What Is the API Management Service?​
Advantages of Using the API Management Service
Integrate API Management with Azure Functions
Summary
Chapter 14:​Deploying Your Azure Functions Using IDEs
Structure of the Chapter
Objective
Deploy an Azure Function to Azure Using Visual Studio 2019
What Are Deployment Slots?​
Deploy an Azure Function to Deployment Slots
Deploy an Azure Function to Azure Using VS Code
Summary
Chapter 15:​Deploying Your Azure Functions Using a CI/​CD
Pipeline with Azure DevOps
Structure of the Chapter
Objectives
What Is Azure DevOps?​
Create a Project in Azure DevOps
Create a Build Pipeline in Azure DevOps and Enable Continuous
Integration
Create a Release Pipeline in Azure DevOps and Enable
Continuous Delivery
Summary
Chapter 16:​Running Azure Functions in Containers
Structure of the Chapter
Objectives
Getting Started with Containers and AKS
What Is Serverless Kubernetes and KEDA in Azure?​
Containerize Azure Functions and Push Them to the Azure
Container Registry
Deploy the Containerized Azure Functions in AKS Using KEDA
Summary
Chapter 17:​Adding Cognitive Capabilities to Your Azure Functions
Structure of the Chapter
Objective
Getting Started with Azure Cognitive Services
Getting Started with Azure Text Analytics
Create an Azure Text Analytics Resource in the Azure Portal
Build a Serverless API to Analyze Feedback Using Sentiment
Analysis
Test the FeedbackAnalyzer​Function Using Postman
Build a Language-Based Document Classifier Serverless
Solution
Test the Language-Based Document Classifier Function
Summary
Chapter 18:​Introduction to Azure Durable Functions
Structure of the Chapter
Objectives
Getting Started with Azure Durable Functions
Benefits of Azure Durable Functions
Application Patterns
Fan-Out and Fan-In
Function Chaining
Async HTTP APIs
Monitoring
Human Interaction
Aggregator
Implement an Azure Durable Function
Summary
Chapter 19:​Integrating Azure Functions in a Logic Apps Workflow
Structure of the Chapter
Objective
Getting Started with Azure Logic Apps
Create an Azure Logic Apps Solution in the Azure Portal
Add Azure Functions in Logic Apps Workflows
Summary
Chapter 20:​Best Practices and Pitfalls to Avoid
Structure of the Chapter
Objectives
Design Guidelines and Best Practices
Decide to Use Functions or Not for Your Scenario
Choose the Correct Programing Language
Choice of Hosting Plan
Pick a Stateful or Stateless Solution
Mitigate Delay Startups
Get the Correct Bill to Fit Your Budget
Handle Long-Running Code
Facilitate Integration and Communication Among Other
Azure and External Services
Identify and Manage the Bottlenecks
Make Your Solution Fault Tolerant
Secure the APIs Developed Using Azure Functions
Facilitate Efficient Monitoring and Debug Failures
Incorporate DevOps Practices and Bring in an IaC Approach
Bring in a Defensive Programming Approach
Pitfalls to Avoid
Sharing Functions in a Single Function App Service
Processing the Input Data One Piece at a Time
Hosting the Production and Development Functions in the
Same Function App Service
Sharing Storage Accounts Across Function App Services
Summary
Index
About the Authors
Ashirwad Satapathi
works as a software developer with a
leading IT firm and has expertise in
building scalable applications with .NET
Core. He has a deep understanding of
building full-stack applications using
.NET Core along with Azure PaaS and
serverless offerings. He is an active
blogger in the C# Corner developer
community. He was awarded the C#
Corner MVP in September 2020 for his
contributions to the developer
community.

Abhishek Mishra
is an architect with a leading multinational software company and has
deep expertise in designing and building enterprise-grade intelligent
Azure and .NET-based architectures. He is an expert in .NET full stack,
Azure (PaaS, IaaS, serverless), infrastructure as code, Azure machine
learning, intelligent Azure (Azure Bot Services and Cognitive Services),
and robotics process automation. He has a rich 15+ years of experience
working in top organizations in the industry. He loves blogging and is
an active blogger in the C# Corner developer community. He was
awarded the C# Corner MVP in December 2018, December 2019, and
December 2020 for his contributions to the developer community.
About the Technical Reviewer
Carsten Thomsen
is primarily a back-end developer but
works with smaller front-end bits as
well. He has authored and reviewed a
number of books and created numerous
Microsoft Learning courses, all focused
on software development. He works as a
freelancer/contractor in various
countries in Europe, using Azure, Visual
Studio, Azure DevOps, and GitHub. He is
an exceptional troubleshooter, asking the
right questions in a most logical to least
logical fashion; he also enjoys working in
the areas of architecture, research,
analysis, development, testing, and bug
fixing. Carsten is a good communicator
with great mentoring and team-lead
skills and is skilled at researching and presenting new material.
© The Author(s), under exclusive license to APress Media, LLC, part of Springer
Nature 2021
A. Satapathi, A. Mishra, Hands-on Azure Functions with C#
https://doi.org/10.1007/978-1-4842-7122-3_1

1. Introduction to Azure Functions


Ashirwad Satapathi1 and Abhishek Mishra2
(1) Gajapati, Odisha, India
(2) Mumbai, Maharashtra, India

Function as a service (FaaS) is getting more popular every day on all


the major cloud platforms. With FaaS, you can build small chunks of
code that run for a short time and host them on the FaaS cloud offering.
You get billed for the time your function runs, and you do not need to
bother about the hosting infrastructure and the scaling aspects.
Microsoft Azure provides Azure Functions as an FaaS offering. You
build your function code and host it on Azure Functions, part of Azure
App Service. The underlying platform takes care of all the hosting and
scaling needs. Executing your code on Azure Functions is cost-effective
most of the time compared to other hosting services available in the
cloud.
In this chapter, you will get a basic understanding of Azure
Functions that will help you grasp the next set of chapters with ease.

Structure of the Chapter


In this chapter, we will explore the following aspects of Azure
Functions:
Introduction to Azure Functions
Introduction to serverless
Azure WebJobs vs. Azure Functions
Advantages and disadvantages of Azure Functions
Hosting plan for Azure Functions
Use cases for Azure Functions

Objectives
After studying this chapter, you will be able to do the following:
Understand the fundamentals of serverless computing and Azure
Functions
Identify scenarios where you can use Azure Functions

Introduction to Azure Functions


Azure Functions is a serverless computing service on the Microsoft
Azure platform and is based on the FaaS computing model. You need to
build your code, spin up a function, and host your code on Azure
Functions. The underlying cloud platform manages the hosting
infrastructure and hosting software. You do not need to worry about
the scaling aspects of your hosted code. The underlying Azure platform
manages all the scaling aspects for your code running on Azure
Functions. You get billed when the function is active and doing its work.
You do not get billed whenever Azure Functions is idle.
Azure Functions hosts code that runs for a short time interval.
However, you can increase the execution time by choosing an
appropriate hosting plan for the function. A function gets invoked and
starts running using triggers. Azure Functions supports a wide range of
triggers. For example, a timer can trigger a function in predefined time
intervals, a new message in the Queue Storage can trigger it, or a simple
HTTP call can trigger a function. Azure Functions interacts with a wide
range of services, such as Blob Storage, Table Storage, Queue Storage,
Event Grid, Cosmos DB, Service Bus Queue, and many more, using
bindings. You can declare both the triggers and the bindings
declaratively without writing any code.
Azure Functions supports three runtime versions and an array of
programming languages based on the runtime you select. 3.x is the
newest runtime, and 1.x is the oldest runtime available. You can build
your code using any of the programming languages in Table 1-1.
Table 1-1 Azure Functions Runtimes and Supported Programming Languages

Language Runtime 1.x Runtime 2.x Runtime 3.x


C# .NET 4.7 .NET Core 2.2 .NET Core 3.1
JavaScript Node 6 Node 10 and 8 Node 12 and 10
F# .NET 4.7 .NET Core 2.2 .NET Core 3.1
Java Not supported Java 8 Java 11 and 8
PowerShell Not supported PowerShell Core 6 PowerShell 7 and Core 6
Python Not supported Python 3.7 and 3.6 Python 3.8, 3.7, and 3.6
TypeScript Not supported Supported Supported
A function executes whenever it gets invoked by a trigger. The
function runs for a particular time interval and gets into an idle state. It
wakes up whenever it gets invoked again by a trigger. The function
takes some time to get warmed up and start executing whenever it gets
triggered.

Introduction to Serverless
You start getting billed for cloud services as soon as you spin them up.
You get billed even if you do not use the services. Also, you need to plan
and configure the scaling strategy for these services. Some services give
you the flexibility to set autoscaling, and for others, you need to set the
scaling configuration manually. In either case, you end up providing the
necessary settings so that the services can scale.
In the serverless cloud services case, you get billed when the service
is running and is executing your hosted code, and you do not get billed
when the service is idle and is not executing anything. You pay the
cloud vendor on an actual consumption basis, which saves you money.
The underlying platform manages all the scaling aspects of your
application running inside the serverless service. You need not
configure any scaling settings for the serverless service. The serverless
services are intelligent enough to add new instances to handle
incoming traffic and remove the additional instances when the
incoming traffic decreases.
Serverless does not mean that the cloud services are not hosted on
any server. You cannot run any code without a server. In the case of
serverless services, you do not have control over the server hosting
your code. You need to bring your code and host it on the serverless
services without worrying about the underlying infrastructure. The
cloud vendor manages the underlying infrastructure.
The following are a few of the popular serverless offerings provided
by Microsoft Azure:
Azure Functions
Azure Logic Apps
Azure Event Grid
Serverless Azure Kubernetes Service
Serverless SQL Database

Note In the case of serverless services and platform as a service


(PaaS), you can get your code and host it on the service without
managing the underlying infrastructure. The cloud vendor manages
the infrastructure. However, you need to manage the scaling aspects
in the case of PaaS. The cloud vendor manages the scaling for the
serverless service. In the case of PaaS, you get billed as soon as you
spin up the service. However, in a serverless service, you get billed
when the service is active and executes your code.

Azure WebJobs vs. Azure Functions


You create a WebJobs job in an App Service Plan. A web job works as a
background worker for your applications hosted on Azure App Service.
For example, you can host an application that facilitates users to upload
files in Azure Blob Storage. Usually, these files will be in a user-specific
format. Before the application processes the files, the files should be
transformed into a standard format that the application can
understand. In such scenarios, you can create a web job in the same
App Service Plan. This web job will run as a background worker, pick up
the user-uploaded file, and transform it into a format that the
application can understand. Web jobs can get triggered using a wide
variety of triggers such as Azure Queue Storage, Cosmos DB, Azure Blob
Storage, Azure Service Bus, Azure Event Hub, and many more. Azure
WebJobs meets all the necessary developer needs for background
processing. However, it shares the same App Service Plan as Azure App
Service. Sharing the same App Service Plan means sharing the same
underlying computing infrastructure. This sharing of the underlying
infrastructure leads to performance bottlenecks at times.
Functions are not just meant to process background tasks. They can
host business logic for applications as well. However, they are well
suited to host code that runs for a short time interval. The functions are
serverless offerings and scale independently. The underlying
infrastructure manages all the scaling aspects for the function. Web
jobs are tied to the Azure App Service instances and scale as and when
the Azure App Service instance scales. You need to set scaling
configurations explicitly for each web job. Functions can run as and
when triggered using consumption-based plans, or they can run
continuously using a Dedicated Plan. Web jobs are always tied to the
App Service Plan that is a dedicated hosting plan. However, you are not
charged separately for web jobs. They come with the App Service Plan.
The Azure portal provides a browser-based editor that you can use to
build, test, and deploy functions inside the Azure portal. This feature
enhances the productivity of the developer. You can integrate Azure
Functions with Azure Logic Apps with ease and build enterprise-grade
solutions on Azure. Azure Functions supports various triggers such as
HTTP WebHooks (GitHub/Slack) and Azure Event Grid that Azure
WebJobs does not support.

Advantages and Disadvantages of Azure Functions


You build your code and host it on Azure Functions without worrying
about the underlying hosting infrastructure. The cloud vendor takes
care of all the hosting aspects such as the hosting server and the
hosting software. As a developer, you get more time to focus on building
your application code and working on its functionality. The underlying
infrastructure scales your application without needing you to configure
the scale settings. Also, you get billed when a function gets triggered
and the code gets executed. This feature saves you money. You can use
Azure Functions with Logic Apps and build truly enterprise-grade
applications. In fact, you can integrate Azure Functions with a wide
range of Azure services with ease. Azure Functions is well suited to
execute code that runs for a short time interval. You can break down
your application functionality into smaller chunks and host it on Azure
Functions. This will help you bring in the single responsibility pattern
at a more granular level. The single responsibility pattern states that a
module or a component of a software program should perform a single
functionality of the program. For example, in a calculator application,
you should have a component or a module that performs an add
operation, a different component that performs a subtract operation,
and so on. The component of the application should be designed to
perform a single functionality instead of doing everything for the
application.
However, functions execute when they get triggered and move into
an idle state when they do not do any work. Whenever a function is idle,
it will take some time for the function to spring into action whenever
triggered. This is because it will take some time for the underlying
infrastructure to get warmed up and start executing the code. This
phenomenon is referred to as a cold-start issue that you must consider
while designing solutions for Azure Functions. At times, Azure
Functions can cost more compared to hosting your code on Azure Web
App. The underlying platform spins up new instances for Azure
Functions whenever the load increases, and you do not have any
control over the scaling aspect. Spinning more instances will increase
the cost of your solution. You should predict the user concurrency for
your application and have the right cost estimate for your solution. In
addition, you should devise an appropriate strategy to control or
manage the user concurrency using queues or some other techniques
and control the Azure Functions’ degree of scalability in your solution.

Hosting Plans for Azure Functions


The hosting plan helps you choose the underlying infrastructure
specification for the function, define how the function should scale, and
set up any other advanced features such as virtual network support
that the function will need. You get billed based on the hosting plan you
choose for Azure Functions. The following are the hosting plans
supported by Azure Functions:
Consumption Plan
Premium Plan
Dedicated Plan

Consumption Plan
In the Consumption Plan case, you do not have control over how the
functions scale. The underlying Azure platform adds or removes
instances on the fly based on the incoming traffic that the functions
receive. You do not have any control over the underlying hosting
infrastructure. You get billed when the function runs. This hosting plan
is an ideal serverless plan, but you may encounter a cold-start
phenomenon. It takes a while for the Azure Functions instances to
warm up and spring into action whenever triggered. Your code does not
run instantaneously when the function is triggered as it takes some
time to wake up from its idle state. This phenomenon is referred to as
the cold-start phenomenon. In the Consumption Plan case, the function
can execute for a maximum of ten minutes and has a default value of
five minutes. The default value of five minutes refers to the amount of
time the function will execute before timing out without explicitly
setting the timeout value for the function.

Premium Plan
In the Premium Plan case, you can have prewarmed Azure Functions
instances that can spring into action and execute the code as soon the
function is triggered. The prewarmed instances help you overcome the
cold-start phenomenon. Like with the Consumption Plan, you do not
have any control over how Azure Functions scales or over the
underlying hosting infrastructure in the Premium Plan case. However,
you get options to choose an SKU (EP1, EP2, or EP3) that will meet the
memory and CPU requirements for your application. The underlying
Azure platform manages all the scaling aspects. You get support for a
virtual network. In the Premium Plan case, you can configure a function
to run for a longer duration without timing out. By default, the function
execution will time out after 30 minutes. Your functions can run
continuously or nearly continuously.

Dedicated Plan
The Dedicated Plan in Azure Functions is the same as the App Service
Plan in Azure WebApp. You get to choose from a wide range of SKUs
and sizes compared to the Premium Plan that will meet the
application’s memory and CPU requirements. You can configure manual
scaling or automatic scaling for your functions. You also get virtual
network support. This hosting plan is best suited for long-running
applications.

Use Cases for Azure Functions


The Azure Functions service can fit into any modern application
patterns and use cases. The following are a few of the best-fit scenarios
where you can use Azure Functions:
You can build an n-tier application using Azure Functions. You can
break the business and data access logic into smaller chunks and
host each of these chunks in a function.
You can run background processing jobs in Azure Functions.
You can use Azure Functions and Durable Functions to build
workflow-based applications where you can orchestrate each of the
workflow steps using Azure Durable Functions and Azure Functions.
You can use Azure Functions to build microservices-based
applications. Each function can host a business service.
You can use Azure Functions to build schedule-based applications
that run on particular time intervals or during a particular time of
day or month or year.
You can build notification systems to trigger a function to notify an
end user or a system based on conditions and events.
You can use Azure Functions in Internet of Things (IoT) scenarios to
implement functions to perform a business activity or process the
ingested data and put it in storage or send it to the next set of
processing.
You can use Azure Functions and Azure Event Grid in event-driven
scenarios where these functions can get triggered and perform a
task.

Summary
In this chapter, you learned the basics of Azure Functions. You explored
what Azure Functions is and discussed the concepts of serverless
computing. You then learned about how Azure WebJobs is different
from Azure Functions and then explored the advantages and
disadvantages of using Azure Functions and the scenarios in which to
use the service. You also learned about the different hosting plans
available for Azure Functions.
The following are the key takeaways from this chapter:
Azure Functions is a serverless computing service on the Microsoft
Azure platform and is based on the FaaS computing model.
You need to build your code, spin up a function, and host your code
on Azure Functions. The underlying cloud platform manages the
hosting infrastructure and hosting software.
The underlying platform manages the scaling aspects for Azure
Functions, and you need not do any scaling configurations.
You get billed when a function executes, and you do not incur any
cost when a function is idle.
Azure Functions supports the Consumption, Premium, and Dedicated
Plans.
You can use Azure Functions in current scenarios like the Internet of
Things, microservices, event-driven applications, and many more.
© The Author(s), under exclusive license to APress Media, LLC, part of Springer
Nature 2021
A. Satapathi, A. Mishra, Hands-on Azure Functions with C#
https://doi.org/10.1007/978-1-4842-7122-3_2

2. Build Your First Azure Function


Ashirwad Satapathi1 and Abhishek Mishra2
(1) Gajapati, Odisha, India
(2) Mumbai, Maharashtra, India

You can create a function for Azure Functions using a wide variety of
options. If you are comfortable with command-line interfaces, then you
can use Azure PowerShell or the Azure command-line interface (CLI).
You can use an integrated development environment (IDE) or a code
editor like Visual Studio IDE or Visual Studio Code. You can also use the
Azure portal to create a function.
In the previous chapter, you learned the basics of the Azure
Functions service and explored some of its essential concepts. In this
chapter, you will explore various options available to create a function.
You will learn how to set up the development prerequisites and explore
how Azure Functions works under the hood.

Structure of the Chapter


In this chapter, we will explore the following topics:
Creating a function using the Azure portal
Creating a function locally using the command line
Creating a function using Visual Studio Code
Creating a function using Visual Studio

Objectives
After studying this chapter, you will be able to do the following:
Understand the core tools of Azure Functions
Create a function using various tooling options

Create Functions Using the Azure Portal


In this section, you’ll create a function in the Azure portal. The Azure
portal provides an in-portal editor to create and customize functions.
To create a function in the Azure portal, you will first have to create a
function app. Then you can create multiple functions inside the function
app.
To create a function app, visit https://portal.azure.com and
log in to the portal using your credentials (Figure 2-1).

Figure 2-1 Sign in to the Azure portal

Once your login is successful, you will get redirected to the Azure
portal dashboard. Type function app in the search bar and click the
Function App option, as shown in Figure 2-2.
Exploring the Variety of Random
Documents with Different Content
CHAPTER III.
THE RIVER CONGO A BOUNDARY—SLAVE
TRADE—SLAVERY—ORDEAL BY POISON—
INSENSIBILITY OF THE NEGRO—INGRATITUDE.

The River Congo, or Zaire, is a very striking and well-marked line


of division or boundary, in respect of climate, fauna, natives and
customs, between Angola and the rest of the West Coast.
The difference in the scenery and vegetation from those of the
north is very great indeed, and not less so is that of the birds and
animals. I have noticed enough to convince me that it would well
repay a naturalist to investigate the number of species this river cuts
off, as it were, from Angola; the gorilla and chimpanzee, for instance,
are only known north of the Congo; they are found at Loango and
Landana, and from reports of the natives, even near to the river
itself; many species of monkeys, very abundant at Cabinda and on
the north bank, are quite unknown in Angola; and the ordinary grey
parrot, which is to be seen in flocks on the Congo, is also unknown
to the south—the only exception to this rule, as far as I have been
able to ascertain, being at Cassange, about 300 miles to the interior
of Loanda, where the rare “King parrot,” with red feathers irregularly
distributed among the grey ones, is not uncommon. Of small birds I
have noticed many at Cabinda that I never observed in Angola; the
same with butterflies, and other insects.
The Congo is very deep, and the current is always very strong;
even above Boma (or M’Boma), about ninety miles distant from the
sea, the river is a vast body of water and the current still very swift.
From the mouth to beyond this place the banks are deeply cut into
innumerable creeks and rivers, and form many large islands. The
enormous quantity of fresh water poured by this river into the sea
gives rise to many curious speculations as to its extent and probable
sources. I am inclined to believe that the River Congo, or its principal
branch, after going in a north-east direction for a comparatively short
distance, bends to the southward, and will be found to run for many
degrees in that direction.
In the preceding chapter we have seen that south of the Congo no
river deserving of that name, or draining more than the country up to
the third elevation, exists in Angola. The vast country from the River
Congo to perhaps the Orange River, or about 1200 miles, has
therefore no outfall for its waters into the Atlantic Ocean.
The existence of volcanic rocks in Cambambe and Mossamedes
appears to explain the elevation of this part of the coast; how much
farther to the south this elevation has taken place is as yet unknown,
and I can only reconcile the vast body of water of the River Congo
with the absence of any large river farther south, by supposing it to
bend down and drain the long line of country upheaved on the
seaboard: it is not likely to drain much country to the north from the
existence of several rivers such as the Chiloango, Quillo, Massabi,
and Mayumba, in a distance of about 360 miles from its mouth to
that of the River Gaboon under the Equator.
For many years, and up to about the year 1868, the Congo was
the principal shipping place for slaves on the South-West Coast, the
large number of creeks in it affording safe hiding-places for loading
the ships engaged in the traffic, and the swift current enabling them
to go out quickly a long way to sea, and clear the line of cruisers.
Boma was the centre or point for the caravans of slaves coming from
different parts of the interior, and there was little or no trade in
produce.
It may not be out of place here to say a few words on the slave-
trade of the South Coast, because a great deal of ignorance and
misconception exists on the subject from judging of it as having been
similar to the slave-trade in North and East Africa. Repugnant and
wicked as is the idea of slavery and dealing in human flesh,
philanthropy must be debited with an amount of unknowing cruelty
and wholesale sacrifice of life perfectly awful to contemplate, as a
set-off against its well-intentioned and successful efforts to put a stop
to slavery and the known horrors of the middle passage, and
subsequent ill-treatment at the hands of the planters.
In no part of Angola or among tribes to the interior have slave-
hunts ever existed as in the north; there are no powerful or more
civilized nations making war on weaker tribes for the purpose of
obtaining slaves, and devastating the country by fire and sword.
There is very little cruelty attending the state of slavery among the
natives of Angola, I believe I may say even in the greater part of the
rest of tropical Africa, but I will restrict myself to the part of which I
have an intimate knowledge. It is a domestic institution, and has
existed, as at present, since time immemorial; and there is no more
disgrace or discredit in having been born of slave parents, and
consequently in being a slave, than there is in Europe in being born
of dependents or servants of an ancestral house, and continuing in
its service in the same manner.
There is something patriarchal in the state of bondage among the
negroes, if we look at it from an African point of view (I must again
impress on my readers that all my remarks apply to Angola). The
free man, or owner, and his wife, have to supply their slaves with
proper food and clothing; to tend them in sickness as their own
children, to get them husbands or wives, as the case may be, to
supply them with the means of celebrating their festivals, such as
their marriages, births, or burials, in nearly the same way as
amongst themselves; the slaves, in fact, are considered as their
family, and are always spoken of as “my son,” or “my daughter.” If
the daughters of slaves are chosen as wives or concubines by their
owners or other free men, it is considered an honour, and their
children, though looked upon as slaves, are entitled to special
consideration.
There is consequently no cruelty or hardship attending the state of
slavery; a male slave cannot be made by his master to cultivate the
ground, which is women’s work, and the mistress and her slaves till
the ground together.
A stranger set down in Angola, and not aware of the existence of
slavery, would hardly discover that such an institution prevailed so
universally amongst them, so little apparent difference is there
between the master and slave. A not very dissimilar condition of
things existed in the feudal times in England and other countries. Yet
many hundred thousand slaves were brought down to the coast to
be sold to the white men and shipped off, and I will now explain how
this was the case, paradoxical though it may appear after what I
have just said. The number was partly made up of surplus slave
population sold off by the owners, probably from inability to feed or
clothe them; cases of famine from failure of the crops, from drought,
&c., a common local occurrence, also supplied large numbers of
slaves; but by far the greatest part were furnished by the effect of
their own laws, almost every offence being punishable by slavery, to
which not only the guilty party, but even in many cases every
member of his family was liable.
Offences against property are especially visited by the severe
penalties of slavery, fine, or death. Any one caught in the act of
stealing, be the amount ever so small, becomes at once the property
or slave of the person robbed. It is a common thing to see blacks
working in chains at factories and houses where they have been
caught stealing, the custom among the Europeans generally being to
detain them until their relatives shall have paid a ransom for them. I
must do the natives the justice to say that they are very observant of
their own laws, even to a white man alone in their territory, who
claims their protection against offenders. Certain offences that we
should consider trifling, are by some tribes visited with heavy
punishment, such as stealing Indian corn whilst growing, or an egg
from under a sitting hen. In other tribes breaking a plate or other
article of crockery is a great offence: this is especially the case to the
interior of Novo Redondo, where the punishment is death or slavery.
I was told there of the amusing manner in which a Portuguese
trader turned the tables on a Soba, or chief of a town, where he had
established himself, and who annoyed him greatly by his constant
demands for presents, by placing a cracked plate under a sheet on
his bed, on which the Soba was in the habit of sitting during his too
frequent visits. On the Soba sitting down as usual, on the trap
prepared for him, he, of course, smashed the plate to atoms, to his
great surprise; frightened at the possible result of the accident, he
humbly begged the trader not to let a soul in the place know of it,
promising restitution; the wished-for result of the scheme was
attained, as he ceased all his importunities during the remainder of
the trader’s stay in the country.
But all these sources of slaves for shipment were but a fraction of
the number supplied by their belief in witchcraft. Witchcraft is their
principal, or only belief; every thing that happens has been brought
about by it; all cases of drought, sickness, death, blight, accident,
and even the most trivial circumstances are ascribed to the evil
influence of witchery or “fetish.”
A “fetish” man is consulted, and some poor unfortunate accused
and either killed at once or sold into slavery, and, in most cases, all
his family as well, and every scrap of their property confiscated and
divided amongst the whole town; in other cases, however, a heavy
fine is imposed, and inability to pay it also entails slavery; the option
of trial by ordeal is sometimes afforded the accused, who often
eagerly demand it, such is their firm belief in it.
This extremely curious and interesting ordeal is by poison, which
is prepared from the thick, hard bark of a large tree, the
Erythrophlæum Guineense (Oliver, ‘Flora of Tropical Africa,’ ii. 320).
Dr. Brunton has examined the properties of this bark, and finds that it
possesses a very remarkable action. The powder, when inhaled,
causes violent sneezing; the aqueous extract, when injected under
the skin of animals, causes vomiting, and has a remarkable effect
upon the vagus nerve, which it first irritates and then paralyses. The
irritation of this nerve makes the heart beat slowly. (Fuller details
may be found in the ‘Proceedings of the Royal Society’ for this year.)
It is called “casca” by the natives, and I obtained a specimen at
Bembe, which was brought to me concealed in rags, by a half-witted
water-carrier in my service, and he procured it for me only after my
promising him that I would not tell anyone. He said it was from a tree
growing about half a day’s journey off, but I could not get him to take
me to it. The other blacks denied all knowledge of it, and said it was
“fetish” for anyone to have it in his possession. On two occasions
afterwards, I obtained some more specimens from natives of
Cabinda, where the tree is said to be abundant, and the natives very
fond of referring all their disputes and accusations to its decision.
“Casca” is prepared by the bark being ground on a stone to a fine
powder, and mixed with about half a pint of cold water, a piece about
two inches square being said to be a dose. It either acts as an
emetic or as a purgative; should the former effect take place, the
accused is declared innocent, if the latter, he is at once considered
guilty, and either allowed to die of the poison, which is said to be
quick in its action, or immediately attacked with sticks and clubs, his
head cut off and his body burnt.
All the natives I inquired of agreed in their description of the effect
produced on a person poisoned by this bark; his limbs are first
affected and he loses all power over them, falls to the ground, and
dies quickly; without much apparent suffering.
It is said to be in the power of the “fetish” man to prepare the
“casca” mixture in such a manner as to determine which of the
effects mentioned shall be produced; in case of a dispute, both
parties drink it, and according as he allows the mixture to settle, and
gives one the clear liquid and the other the dregs, so does it produce
vomiting in the former, and acts as a purgative in the latter case. I
have very little doubt that as the “fetish” man is bribed or not, so he
can and does prepare it.
The Portuguese in Angola strictly prohibit the use of “casca,” and
severely punish any natives concerned in a trial by this bark, but it is
nevertheless practised in secret everywhere.
The occasion of the test is one of great excitement, and is
accompanied by much cruelty. In some tribes the accused, after
drinking the potion, has to stoop and pass under half-a-dozen low
arches made by bending switches and sticking both ends into the
ground; should he fall down in passing under any of the arches, that
circumstance alone is sufficient to prove him guilty, without waiting
for the purgative effect to be produced.
Before the trial the accused is confined in a hut, closely guarded,
and the night before it is surrounded by all the women and children
of the neighbouring towns, dancing and singing to the horrid din of
their drums and rattles. On the occasion of the ordeal the men are all
armed with knives, matchets, and sticks, and the moment the poor
devil stumbles in going under one of the switches, he is instantly set
upon by the howling multitude and beaten to death, and cut and
hacked to pieces in a few minutes. I was at Mangue Grande on one
occasion when a big dance was going on the night before a poor
wretch was to take “casca.” I went to the town with some of the
traders at that place, and we offered to ransom him, but to no
purpose; nothing, they said, could save him from the trial. I learnt,
however, that he passed it successfully, but I think I never heard
such a hideous yelling as the 400 or 500 women and children were
making round the hut, almost all with their faces and bodies painted
red and white, dancing in a perfect cloud of dust, and the whole
scene illuminated by blazing fires of dry grass under a starlit summer
sky.
The most insignificant and extraordinary circumstances are made
the subject of accusations of witchcraft, and entail the usual
penalties.
I was at Ambrizzette when three Cabinda women had been to the
river with their pots for water; all three were filling them from the
stream together, when the middle one was snapped up by an
alligator, and instantly carried away under the surface of the water,
and of course devoured. The relatives of the poor woman at once
accused the other two of bewitching her, and causing the alligator to
take her out of their midst! When I remonstrated with them, and
attempted to show them the utter absurdity of the charge, their
answer was, “Why did not the alligator take one of the end ones
then, and not the one in the middle?” and out of this idea it was
impossible to move them, and the poor women were both to take
“casca.” I never heard the result, but most likely one or both were
either killed or passed into slavery.
At a place near the mountain range of Pungo Andongo, about 150
miles inland of Loanda, I was once the amused spectator at a
curious trial of a man for bewitching the spirit of his dead wife. Her
sister, it appeared, suffered from violent headaches, and sleepless
nights, which were said to be caused by the wife’s spirit being unable
to rest, on account of the widower being a wizard. A large circle of
spectators was formed round the sick sister, who was squatting on
the ground; a fetish man was beating a drum, and singing, or rather
droning, some incantation; after a little while, the woman began to
give short yelps, and to close her eyes, and on being interrogated by
the fetish man, said the spirit of her sister had spoken to her, and
that she could not rest until her husband had made restitution of her
two goats and her baskets, &c., which he had appropriated, and
which she had desired should be given to her sister. The man
instantly rose, and brought the goats, baskets, clothes, &c., and laid
them before his sister-in-law, and the trial was over. If he had denied
the accusation, he would inevitably have had to take “casca.”
When we consider the great population of the vast country that
supplied the slave trade of the coast, and that, as I have explained,
the state of their laws and customs renders all transgressions liable
to slavery, the absence of necessity for the slave wars and hunts of
the north of Africa and other extensive and thinly populated districts
is sufficiently proved. I have been unable to collect positive
information as to the statistics of the slaves shipped in Angola (from
Congo to Benguella inclusively), but the number could not have been
far short of 100,000 per annum. I was told by some of the old
inhabitants, that to see as many as ten to twelve vessels loading at a
time at Loanda and Benguella was a common occurrence. At the
time of the last shipments from Benguella, about ten years ago, I
have seen as many as 1000 slaves arrive in one caravan from the
interior, principally from Bihé.
Up to within a very few years there existed a marble arm-chair on
the wharf at the custom-house at Loanda, where the bishop, in the
slave-trading times, was wont to sit, to baptize and bless the batches
of poor wretches as they were sent off in barge-loads to the vessels
in the harbour. The great slaughter now going on in a great part of
Africa, which I have mentioned as the result of the suppression of
the slave shipments from the coast, can now be understood;
whereas formerly they were sent to the coast to be sold to the white
men and exported, they are now simply murdered. On the road down
from Bembe in April last, we passed the ashes and bones of a black
who had stolen a trade-knife, a bit of iron in a small wooden handle,
and made in Germany at the rate of a few shillings per gross, and
passed on the coast in trade; on the top of his staff was stuck his
skull and the knife he had stolen, a ghastly and lasting warning to
passersby of the strict laws of the country respecting property.
If a famine overtakes any part of the country, a common
occurrence, the slaves are simply taken out and knocked on the
head to save them from starvation. I was told by the natives that the
slaves offered no resistance to that fate, but accepted it as
inevitable, and preferable to the pangs of hunger, knowing that it was
no use going to the coast to save their lives at the hands of the white
men by being shipped as slaves. At Musserra, three Cabinda blacks
from the boats’ crews joined three natives in robbing one of the
factories: on complaint being made to the king and principal men of
the town, they marched off the three Cabindas, promising to punish
them, which they did by cutting off their heads, unknown to the white
men; they then brought the three natives to deliver up to the traders
as their slaves, but on these refusing to accept them, and
demanding that a severe punishment should also be passed on
them, they quietly tied a large stone to their necks, took them out in a
canoe to the bay, and dropped them into the sea.
It is impossible to reclaim the hordes of savages inhabiting the
interior even of Angola from their horrid customs and their disregard
for life; the insalubrity of the country, though it is infinitely superior in
this respect to the rest of the West Coast, would be an almost
insuperable bar to their improvement; their own progress is still more
hopeless. In my opinion, it would be necessary that tropical Africa
should undergo a total physical revolution, that the long line of
unhealthy coast should be upheaved, and the deadly leagues of
pestiferous swamps be thus drained, before the country would be
fitted for the existence of a higher type of mankind than the present
negro race.
It can only have been by countless ages of battling with malaria,
that they have been reduced physically and morally to their present
wonderful state or condition of withstanding successfully the climatic
influences, so fatal to the white and more highly organized race—the
sun and fevers of their malignant and dismal mangrove swamps, or
the mists and agues of their magnificent tropical forests, no more
affecting them than they do the alligators and countless mosquitoes
that swarm in the former, or the monkeys and snakes that inhabit the
latter. It is really astonishing to see the naked negro, without a
particle of covering on his head (often shaved), in the full blaze of the
fierce sun, his daily food a few handfuls of ground-nuts, beans, or
mandioca-root, and very often most unwholesome water for drink. At
night he throws himself on the ground, anywhere, covers himself
with a thin grass or cotton cloth, nearly transparent in texture, without
a pillow, like a dog, and awakes in the morning generally wet through
with the heavy dew, and does not suffer the least pain or
inconvenience from the climate from infancy to old age unless his
lungs become affected.
The way babies are treated would be enough to kill a white child.
The women when at work on the plantations generally place them on
a heap of grass or on the ground, and are not at all particular to put
them in the shade, and I have often seen them naked and filthy, and
covered with a thick mass of large buzzing flies over their faces and
bodies, fast asleep, with the sun shining full on them. The women, in
carrying them tied behind their backs, seldom include their little
heads in the cloth that secures them, but leave them to swing and
loll about helplessly in every direction with the movement of walking.
Children, of any age, seldom cry, and when they do it is a kind of
howl; when hurt or punished, they very rarely shed tears, or sob, but
keep up a monotonous noise, which would never be imagined to be
the crying of a child, but rather a song.
I once saw, in one of the market-places in Loanda, a boy of about
sixteen lying on the ground, nearly naked, with his face and body
covered with flies, but none of the busy thronging crowd had thought
that he was dead and stiff, as I discovered when I touched him with
my foot, but thought he was simply asleep and basking in the sun:
his being covered with flies was too trivial a circumstance to attract
any attention.
The manner in which negroes receive most severe wounds, with
apparently little pain and absence of nervous shock, is most
extraordinary. I have often been told of this by the Portuguese
surgeons, who remark the absence of shock to the system with
which negroes undergo amputations and other severe operations
(without chloroform), which are attended by so much danger to the
white race. I was staying at Ambrizzette when a man came there
with his right hand blown to a mass of shreds, from the explosion of
a gun-barrel; he was accompanied by his relatives, who took him to
the different factories to beg the white men to cut off the hanging
shreds of flesh and dress the injured part. All refused to attend to the
man, till a Frenchman gave them a sharp razor, arnica, and balsam,
and some bandages, and made them go out of the house and
enclosure to operate on the sufferer themselves, away from the
factories; which they did. About an hour after I was passing a group
of natives sitting round a fire, and amongst them was the wounded
man laughing and joking quite at his ease, and with his left hand
roasting ground-nuts with the rest, as if nothing had happened to
him.
The reason the white men refused to help the wounded black was
not from want of charity or pity, as all would have done everything in
their power to alleviate his sufferings, but it was the singular custom
of the natives that prevented their doing so. Had he died, the white
man who ministered to him would have been made responsible for
his death, and would have been almost as heavily fined as if he had
murdered him! If he got well, as he did, his benefactor would have
been inconvenienced by heavy demands for his maintenance and
clothing, and expected to make presents to the king, &c., for he
would be looked upon as having saved his life, and consequently
bound to support him, to a certain extent, as he was, though alive,
unable from the accident to get his own living as readily as if he were
uninjured. The Frenchman got over this risk by giving the remedies,
not to the wounded black himself, but to his friends, and also making
them clear out of the precincts of the house; so that in no case,
whether the man died or lived, could any claim be made against him.
The only way to put a stop to the awful bloodshed now going on in
the interior would be to organize an emigration scheme, under the
direct supervision of the several governments who have entered into
treaties for the abolition of slavery, and transport the poor wretches,
now being murdered in cold blood by thousands, to tropical climates
where they might earn their living by the cultivation of those articles
necessary for consumption in civilized countries; their constitution
would enable them to resist the climate, and they would gradually
become civilized.
One great bar to their civilization in Angola, is that no tribe on the
coast can be induced to work for wages, except as servants in
houses and stores, and even these are mostly slaves of other
natives, or work to pay off some fine or penalty incurred in their
towns. For some years that I have been collecting the inner bark of
the Adansonia digitata, or Baobab tree (the application of which to
paper-making I discovered in 1858, and commenced working as a
commercial speculation in 1865), I have been unable to induce one
single native to hire himself to work by day or piecework; they will
cut, prepare, and dry it, and bring it for sale, but nothing will induce
them to hire themselves, or their slaves, to a white man.
There are at present in Angola several sugar and cotton
plantations worked by slaves, called at present “libertos,” who are
meant by the Portuguese Government to work ten years, as a
compensation to their owners for the capital expended in their
purchase and for their clothing, education and medical treatment. At
a near date, the total abolition of slavery in Angola has been
decreed, and will come into force; with the inevitable result of the
ruin of the plantations, or of its becoming a dead letter in the
province.
By the native laws, a black once sold as a slave, and escaping
back to his tribe, is considered a free man, so that a planter at
present has no hold on his slaves; if they escape into the
neighbouring towns, the natives will only deliver them up on the
payment of a certain amount, very often more than he had cost in
the first instance.
No amount of kindness or good done to a negro will have the
slightest influence in preventing him from leaving his benefactor
without as much as a “good-bye,” or a shadow of an excuse, and
very often going from a pampered existence to the certainty of the
hard fare and life of their free condition, and this, not from the
slightest idea of love of freedom, or anything of the kind, but simply
from an animal instinct to live a lazy and vegetative existence.
When I was at Cuio, working a copper deposit, a black called
Firmino, the slave of a Portuguese there, attached himself very much
to me, and was, seemingly, never so happy as when accompanying
me in my trips and rambles, and not from any payment I gave him,
beyond a small and occasional present. When his master was
leaving the place, Firmino came crying to me, begging me to buy
him, that he might remain in my service as my slave, promising that
he would never leave me.
His master generally treating him with harshness, if not cruelty, I
took pity on him, and gave 13l. 10s. for him, a high and fancy price
there, but he was considered worth it from his great size and
strength, his speaking Portuguese perfectly, and good qualities
generally.
I explained to him that although I had bought him, he was a free
man, and could go at once if he liked; but that as long as he
remained in my service as my personal attendant, he should have
clothes and pay. He went on his knees to thank me and to swear in
negro fashion, by making a cross in the dust with his forefinger, that
he would never leave me. A fortnight after, having to send him with a
bundle of clothes from Benguella to Cuio, he delivered them to the
person they were addressed to, but joined three slaves in stealing a
boat and sailing to Loanda.
A month after I received a letter from the police there advising me
that a nigger called Firmino had been caught with others in an
extensive robbery, and claimed to be my slave. I answered that he
was no slave of mine, detailing the circumstances of my freeing him,
and asking that he should be dealt with as he deserved. He was
punished and drafted as a soldier at Loanda, and on my meeting him
there one day and asking him his reason for leaving me, and treating
me so ungratefully, he said that “he did not know why he had done
so;” and I do not believe he did, or ever tried to find out, or bothered
his head any more about it.
It is no use disguising the fact that the negro race is, mentally,
differently constituted from the white, however disagreeable and
opposed this may be to the usual and prevailing ideas in this country.
I do not believe, and I fearlessly assert, that there is hardly such a
thing possible as the sincere conversion of a single negro to
Christianity whilst in Africa, and under the powerful influence of their
fellows. No progress will be made in the condition of the negro as
long as the idea prevails that he can be reasoned out of his
ignorance and prejudices, and his belief in fetish, or that he is the
equal of the white man; in fact, he must remain the same as he is
now, until we learn to know him properly, and what he really is.
Loanda was discovered in the year 1492, and since 1576 the
white race has never abandoned it. The Jesuits and other
missionaries did wonders in their time, and the results of their great
work can be still noticed to this day: thousands of the natives, for 200
miles to the interior, can read and write very fairly, though there has
hardly been a mission or school, except in a very small way, at
Loanda itself, for many many years; but those accomplishments are
all that civilization or example has done amongst them. They all
believe firmly in their fetishes and charms, and though generally
treated with the utmost kindness and equality by the Portuguese, the
negro race, and even the mulattoes, have never advanced further
than to hold secondary appointments, as writers or clerks, in the
public offices and shops, and to appear (in public) in the most
starched and dandyfied condition. I can only recollect one black man
who had at all distinguished himself in trade; keeping low and filthy
grog-shops being about the extent of their business capacity.
Another honourable exception is a Captain Dias, who is the captain
or governor of the district of the “Barra do Bengo,” near Loanda, a
very intelligent man, and from whom I several times experienced
great kindness and hospitality.

Plate II.
porto da lenha.
To face page 81.
CHAPTER IV.
THE RIVER CONGO—BANANA—PORTO DA
LENHA—BOMA—MUSSURONGO TRIBE—
PIRATES—MUSHICONGO TRIBE—FISH—PALM
CHOP—PALM WINE.

At the mouth of the River Congo and on its north bank a long spit
of sand separates the sea from a small creek or branch of the river.
On this narrow strip, called Banana, are established several
factories, belonging to Dutch, French, and English houses, and
serving principally as depôts for their other factories higher up the
river and on the coast. The Dutch house especially is a large
establishment, and it was in one of their small steamers that my wife
and myself ascended the river in February 1873.
The first place we touched at was Porto da Lenha, about forty or
forty-five miles from Banana. The river banks up to this point are
sheer walls of large mangrove trees rising out of the water; at high
water, particularly, hardly a dry place can be seen where one could
land from a boat or canoe. The natives have, of course, openings
known to themselves, under and through the mangrove, where their
little canoes dart in and out.
Porto da Lenha (Plate II.) consists of half-a-dozen trading
factories, built on ground enclosed from the river by piles, forming
quays in front, where large vessels can discharge and load close
alongside. The wharves are continually sinking, and have to be
replaced by constant addition of new piles and layers of thick fresh-
water bivalve shells, very abundant in the river. We here found
growing in the mud, and with the roots covered by the river at high
water, the lovely orchid “Lissochilus giganteus” in full bloom; we
collected some of its roots, which reached England safely, and are
now growing in Kew Gardens. Several fine creepers were also in
flower, and we observed numerous butterflies, which were not easy
to capture from the difficulty of getting at them, as at the back of the
houses the dense bush grows out of swamp, and only those
specimens crossing the small dry space on which the houses are
built could be collected. Little creeks divide one house from another;
in some cases a plank bridge affords communication, but it is mostly
effected by boats. A few days before our arrival a flood had covered
the whole of the ground with several inches of water. Considering the
conditions of the place, it does not seem to be so unhealthy to
Europeans as might be expected. Next day we proceeded to Boma,
also situated on the north bank of the river, about ninety-five miles
from Banana.
The scenery completely changes after leaving Porto da Lenha, the
mangrove totally disappears, and several kinds of bright green
bushes, interspersed with different palms and trees, cover the banks
for many miles. Near Boma, however, the banks are higher, and
become bare of trees and shrubs, the whole country being
comparatively free of any other vegetation but high grass; we have
arrived, in fact, at the grass-covered high country before mentioned
as beginning at the third elevation from the coast over the whole of
Angola.
We were most hospitably received by a young Portuguese,
Senhor Chaves, in charge of an English factory there, picturesquely
situated, overlooking the banks of the river. A high hill opposite
Boma and across the river is covered from the top right down to the
water’s edge with an impenetrable forest, and it is not easy to
explain this vegetation, as it stands in such singular relief to the
comparative barrenness of the surrounding country, gigantic
Baobabs being the great tree-feature of the place. We crossed the
river several times to this thickly-wooded hill, and were only able to
find just sufficient shore to land under the branches of the trees, one
of which (Lonchocarpus sericeus) was in beautiful bloom. The
current of the river is so strong, and the stream so broad, that it took
us half-an-hour to get across in a good boat with ten strong Kroomen
paddling.
The view from a high hill on the north bank is magnificent: a
succession of bends of the river, and as far as the sight could reach,
the flat country to the south and west cut into innumerable islands
and creeks, of the brightest green of the water-grass and papyrus
reed, divided by the sunlit and quicksilver-like streams of the vast
rapidly-flowing river.
Boma, as before observed, was formerly the great slave-trade
mart, thousands arriving from all quarters of the interior; they
generally carried a load of provisions, chiefly small beans, a species
of the haricot, for sale to the traders, and on which the slaves were
chiefly fed, in the barracoons and on board the vessels in which they
were shipped, and the Congo used in this way to supply the coast,
even to Loanda, with abundance of beans, mandioca-meal, &c.; but
since the cessation of the slave-trade there has been such great
scarcity of native grown food produce, not only in the river but
everywhere on the coast—the cultivation of other products, such as
ground-nuts, being of greater advantage to the natives—that
Europeans are sometimes reduced to great straits for food for the
natives in their service, and even for the fowls. This is one of the
curious changes produced in the country by the abolition of the
slave-trade. A very large trade quickly sprang up at Boma in ground-
nuts, palm-oil, palm-kernels, &c.; but a foolish competition amongst
the white traders has induced them to go higher up the river to trade;
the consequence has been that Boma, so capitally situated in every
way for a trading station, is now nearly reduced to a depôt for
produce brought from farther up the river.
We were a fortnight at Boma, but were greatly disappointed at the
small number of species of insects we collected, and the poverty in
plants as well. All the lovely coloured finches and other birds of the
grassy regions were here most conspicuous in number and
brilliancy, and it was really beautiful to see the tall grass alive with
the brightest scarlet, yellow, orange, and velvet black of the many
different species, at that season in their full plumage.
We were very much amused at a pretty habit of the males of the
tiny little sky-blue birds (Estrelda cyanogastra) that, with other small
birds such as the Spermestes, Estreldas, Pytelias, &c., used to come
down in flocks to feed in the open space round the house. The little
mites would take a grass flower in their beaks, and perform quite a
hoppy dance on any little stick or bush, bobbing their feathery heads
up and down, whilst their tiny throats swelled with the sweetest little
song-notes and trills imaginable. This was their song to the females,
who were feeding about on the ground below them. The long-tailed
little whydah birds (Vidua principalis) have a somewhat similar habit
of showing off whilst the hens are feeding on the ground; they keep
hovering in the air about three or four feet above them, twit-twitting
all the time, their long tails rising and falling most gracefully to the
up-and-down motion of their little bodies.
One Sunday during our stay Senhor Chaves organized a pic-nic of
the principal white traders to a native village in the interior, where he
had arranged that the nine kings who govern Boma and receive
“customs” from the traders, should meet us, in order that he might
make them each a “dash,” which he wished my wife to present, in
commemoration of a white woman’s visit. We started in hammocks,
and after about two hours’ journey, arrived at the place of meeting,
where a good breakfast awaited us. Our road was over hilly ground,
rough and rocky (mica schist), and was remarkably bare of
vegetation; we passed one or two large and well-cultivated ravines.
After breakfast the nine kings appeared on the scene, and a
miserable lot they were, with one exception, a fine tall old grizzly
negro; their retinues were of the same description, and wretchedly
clad. There was a big palaver, the customary amount of rum was
consumed by them, and they each received, from my wife, their
“dress” of several yards of cloth, piece of cotton handkerchiefs, red
baize sash, and red cotton nightcap. One old fellow had a very
curious old crucifix, which he did not know the age of; he could only
tell that he was the fifth Soba or king that had inherited it. It had
evidently belonged to the old Catholic Portuguese missionaries of
former times.
Crucifixes are often seen as “fetishes” of the kings in Angola.
Nothing will induce them to part with them, as they belong to part of
the “fetishes” that have been handed down from king to king from
time immemorial, and must not be lost or disposed of.
An amusing incident occurred on our way at a large village, where
a great crowd, chiefly of women and children, had collected to cheer
the white woman, seen for the first time in their lives. My hammock
was a little way behind, and on arriving at the village I was met with
great shouts and much shaking of hands; as the other white men
had not been similarly received, I inquired the reason why, and was
then informed that it was to denote their satisfaction at seeing the
“proprietor or owner of the white woman,” as they expressed it.
The natives here, in fact above Porto da Lenha, are Mushicongos,
and are not a bad set of blacks; but, like all this large tribe, are weak
and puny in appearance, dirty in their habits, and scanty of clothing.
They have not as yet allowed white men to pass from Boma, or any
other point of the river, to St. Salvador, and several Portuguese who
have wished to go from St. Salvador to Boma have been dissuaded
from attempting the journey by the king and natives, not from any
objection on their part, but from the certainty that the blacks near the
river would make them turn back.
There is a very great objection on the part of all the tribes of the
interior of Angola, and particularly of those not in the actual territory
held by the Portuguese, to the passage of a white man through the
country. This is due in the first place to the natural distrust and
suspicion of the negro character, and secondly to their fear of the
example of the occupation of Ambriz and the Bembe mines by the
Portuguese. It is impossible for blacks to understand that a white
man will travel for curiosity’s sake; it is perfectly incomprehensible to
them that he should spend money in carriers, making presents, &c.,
only for the pleasure of seeing the country; they are never satisfied
without what they consider a good reason; consequently they always
imagine it must be for the purpose of establishing a factory for trade,
or else to observe the country for its occupation thereafter. This is
the reason why natives will never give reliable information regarding
even the simplest question of direction of roads, rivers, distances,
&c. It is very difficult to obtain exact information, and it is only after
being very well acquainted with them that their natural suspicions are
lulled, and they will freely afford the knowledge desired.

You might also like